mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-29 13:28:14 +00:00
Add support for hardware unicast; use send_packet instead of sendto; get interface address from packet rather than searching the list.
This commit is contained in:
parent
045820eec6
commit
fde927d2f5
13
bootp.c
13
bootp.c
@ -57,6 +57,7 @@ void bootp (packet)
|
|||||||
struct packet outgoing;
|
struct packet outgoing;
|
||||||
struct dhcp_packet raw;
|
struct dhcp_packet raw;
|
||||||
struct sockaddr_in to;
|
struct sockaddr_in to;
|
||||||
|
struct hardware hto;
|
||||||
struct tree_cache *options [256];
|
struct tree_cache *options [256];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ void bootp (packet)
|
|||||||
hp -> fixed_addr -> tree);
|
hp -> fixed_addr -> tree);
|
||||||
memcpy (&raw.yiaddr, hp -> fixed_addr -> value,
|
memcpy (&raw.yiaddr, hp -> fixed_addr -> value,
|
||||||
sizeof raw.yiaddr);
|
sizeof raw.yiaddr);
|
||||||
raw.siaddr.s_addr = pick_interface (packet);
|
memcpy (&raw.siaddr, packet -> interface -> address.iabuf, 4);
|
||||||
raw.giaddr = packet -> raw -> giaddr;
|
raw.giaddr = packet -> raw -> giaddr;
|
||||||
if (hp -> server_name) {
|
if (hp -> server_name) {
|
||||||
strncpy (raw.sname, hp -> server_name,
|
strncpy (raw.sname, hp -> server_name,
|
||||||
@ -157,9 +158,13 @@ void bootp (packet)
|
|||||||
packet -> raw -> chaddr),
|
packet -> raw -> chaddr),
|
||||||
inet_ntoa (packet -> raw -> yiaddr));
|
inet_ntoa (packet -> raw -> yiaddr));
|
||||||
|
|
||||||
|
hto.htype = packet -> raw -> htype;
|
||||||
|
hto.hlen = packet -> raw -> hlen;
|
||||||
|
memcpy (hto.haddr, packet -> raw -> chaddr, hto.hlen);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result = sendto (packet -> client_sock, &raw, outgoing.packet_length,
|
result = send_packet (packet -> interface,
|
||||||
0, (struct sockaddr *)&to, sizeof to);
|
packet, &raw, outgoing.packet_length, &to, &hto);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
warn ("sendto: %m");
|
warn ("send_packet: %m");
|
||||||
}
|
}
|
||||||
|
41
dhcp.c
41
dhcp.c
@ -155,7 +155,8 @@ void dhcprequest (packet)
|
|||||||
we have a lease for this client, let it go. */
|
we have a lease for this client, let it go. */
|
||||||
if (memcmp (packet ->
|
if (memcmp (packet ->
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER].data,
|
options [DHO_DHCP_SERVER_IDENTIFIER].data,
|
||||||
siaddr.iabuf, siaddr.len)) {
|
packet -> interface -> address.iabuf,
|
||||||
|
packet -> interface -> address.len)) {
|
||||||
if (lease)
|
if (lease)
|
||||||
release_lease (lease);
|
release_lease (lease);
|
||||||
return;
|
return;
|
||||||
@ -237,6 +238,7 @@ void nak_lease (packet, cip)
|
|||||||
struct dhcp_packet raw;
|
struct dhcp_packet raw;
|
||||||
unsigned char nak = DHCPNAK;
|
unsigned char nak = DHCPNAK;
|
||||||
struct packet outgoing;
|
struct packet outgoing;
|
||||||
|
struct hardware hto;
|
||||||
|
|
||||||
struct tree_cache *options [256];
|
struct tree_cache *options [256];
|
||||||
struct tree_cache dhcpnak_tree;
|
struct tree_cache dhcpnak_tree;
|
||||||
@ -272,7 +274,7 @@ void nak_lease (packet, cip)
|
|||||||
cons_options (packet, &outgoing, options, 0);
|
cons_options (packet, &outgoing, options, 0);
|
||||||
|
|
||||||
/* memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/
|
/* memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/
|
||||||
memcpy (&raw.siaddr, siaddr.iabuf, 4);
|
memcpy (&raw.siaddr, packet -> interface -> address.iabuf, 4);
|
||||||
raw.giaddr = packet -> raw -> giaddr;
|
raw.giaddr = packet -> raw -> giaddr;
|
||||||
memcpy (raw.chaddr, packet -> raw -> chaddr, sizeof raw.chaddr);
|
memcpy (raw.chaddr, packet -> raw -> chaddr, sizeof raw.chaddr);
|
||||||
raw.hlen = packet -> raw -> hlen;
|
raw.hlen = packet -> raw -> hlen;
|
||||||
@ -290,7 +292,7 @@ void nak_lease (packet, cip)
|
|||||||
to.sin_addr = raw.giaddr;
|
to.sin_addr = raw.giaddr;
|
||||||
to.sin_port = server_port;
|
to.sin_port = server_port;
|
||||||
} else {
|
} else {
|
||||||
memcpy (&to.sin_addr.s_addr, cip->iabuf, 4);
|
to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
|
||||||
to.sin_port = packet->client_port;
|
to.sin_port = packet->client_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,9 +308,14 @@ void nak_lease (packet, cip)
|
|||||||
packet -> raw -> chaddr),
|
packet -> raw -> chaddr),
|
||||||
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
||||||
|
|
||||||
|
hto.htype = packet -> raw -> htype;
|
||||||
|
hto.hlen = packet -> raw -> hlen;
|
||||||
|
memcpy (hto.haddr, packet -> raw -> chaddr, hto.hlen);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result = sendpkt (packet, &raw, outgoing.packet_length,
|
result = send_packet (packet -> interface,
|
||||||
(struct sockaddr *) &to, sizeof(to));
|
packet, &raw, outgoing.packet_length,
|
||||||
|
&to, (struct hardware *)0);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
warn ("sendpkt: %m");
|
warn ("sendpkt: %m");
|
||||||
|
|
||||||
@ -334,6 +341,7 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
struct dhcp_packet raw;
|
struct dhcp_packet raw;
|
||||||
struct tree_cache *options [256];
|
struct tree_cache *options [256];
|
||||||
struct sockaddr_in to;
|
struct sockaddr_in to;
|
||||||
|
struct hardware hto;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
struct tree_cache dhcpoffer_tree;
|
struct tree_cache dhcpoffer_tree;
|
||||||
@ -486,9 +494,12 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
options [DHO_DHCP_MESSAGE_TYPE] -> tree = (struct tree *)0;
|
options [DHO_DHCP_MESSAGE_TYPE] -> tree = (struct tree *)0;
|
||||||
|
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] = &server_id_tree;
|
options [DHO_DHCP_SERVER_IDENTIFIER] = &server_id_tree;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> value = siaddr.iabuf;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> value =
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> len = siaddr.len;
|
packet -> interface -> address.iabuf;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> buf_size = siaddr.len;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> len =
|
||||||
|
packet -> interface -> address.len;
|
||||||
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> buf_size =
|
||||||
|
packet -> interface -> address.len;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> timeout = 0xFFFFFFFF;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> timeout = 0xFFFFFFFF;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> tree = (struct tree *)0;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> tree = (struct tree *)0;
|
||||||
|
|
||||||
@ -541,7 +552,7 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
|
|
||||||
raw.ciaddr = packet -> raw -> ciaddr;
|
raw.ciaddr = packet -> raw -> ciaddr;
|
||||||
memcpy (&raw.yiaddr, lease -> ip_addr.iabuf, 4);
|
memcpy (&raw.yiaddr, lease -> ip_addr.iabuf, 4);
|
||||||
memcpy (&raw.siaddr, siaddr.iabuf, 4);
|
memcpy (&raw.siaddr, packet -> interface -> address.iabuf, 4);
|
||||||
raw.giaddr = packet -> raw -> giaddr;
|
raw.giaddr = packet -> raw -> giaddr;
|
||||||
|
|
||||||
raw.xid = packet -> raw -> xid;
|
raw.xid = packet -> raw -> xid;
|
||||||
@ -566,7 +577,7 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
|
|
||||||
/* Otherwise, broadcast it on the local network. */
|
/* Otherwise, broadcast it on the local network. */
|
||||||
} else {
|
} else {
|
||||||
memcpy (&to.sin_addr.s_addr, lease -> ip_addr.iabuf, 4);
|
to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
|
||||||
to.sin_port = htons (ntohs (server_port) + 1); /* XXX */
|
to.sin_port = htons (ntohs (server_port) + 1); /* XXX */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,9 +594,13 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
packet -> raw -> chaddr),
|
packet -> raw -> chaddr),
|
||||||
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
||||||
|
|
||||||
errno = 0;
|
hto.htype = packet -> raw -> htype;
|
||||||
result = sendpkt (packet, &raw, outgoing.packet_length,
|
hto.hlen = packet -> raw -> hlen;
|
||||||
(struct sockaddr *) &to, sizeof(to));
|
memcpy (hto.haddr, packet -> raw -> chaddr, hto.hlen);
|
||||||
|
|
||||||
|
result = send_packet (packet -> interface,
|
||||||
|
packet, &raw, outgoing.packet_length,
|
||||||
|
&to, &hto);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
warn ("sendpkt: %m");
|
warn ("sendpkt: %m");
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ void bootp (packet)
|
|||||||
struct packet outgoing;
|
struct packet outgoing;
|
||||||
struct dhcp_packet raw;
|
struct dhcp_packet raw;
|
||||||
struct sockaddr_in to;
|
struct sockaddr_in to;
|
||||||
|
struct hardware hto;
|
||||||
struct tree_cache *options [256];
|
struct tree_cache *options [256];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ void bootp (packet)
|
|||||||
hp -> fixed_addr -> tree);
|
hp -> fixed_addr -> tree);
|
||||||
memcpy (&raw.yiaddr, hp -> fixed_addr -> value,
|
memcpy (&raw.yiaddr, hp -> fixed_addr -> value,
|
||||||
sizeof raw.yiaddr);
|
sizeof raw.yiaddr);
|
||||||
raw.siaddr.s_addr = pick_interface (packet);
|
memcpy (&raw.siaddr, packet -> interface -> address.iabuf, 4);
|
||||||
raw.giaddr = packet -> raw -> giaddr;
|
raw.giaddr = packet -> raw -> giaddr;
|
||||||
if (hp -> server_name) {
|
if (hp -> server_name) {
|
||||||
strncpy (raw.sname, hp -> server_name,
|
strncpy (raw.sname, hp -> server_name,
|
||||||
@ -157,9 +158,13 @@ void bootp (packet)
|
|||||||
packet -> raw -> chaddr),
|
packet -> raw -> chaddr),
|
||||||
inet_ntoa (packet -> raw -> yiaddr));
|
inet_ntoa (packet -> raw -> yiaddr));
|
||||||
|
|
||||||
|
hto.htype = packet -> raw -> htype;
|
||||||
|
hto.hlen = packet -> raw -> hlen;
|
||||||
|
memcpy (hto.haddr, packet -> raw -> chaddr, hto.hlen);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result = sendto (packet -> client_sock, &raw, outgoing.packet_length,
|
result = send_packet (packet -> interface,
|
||||||
0, (struct sockaddr *)&to, sizeof to);
|
packet, &raw, outgoing.packet_length, &to, &hto);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
warn ("sendto: %m");
|
warn ("send_packet: %m");
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,8 @@ void dhcprequest (packet)
|
|||||||
we have a lease for this client, let it go. */
|
we have a lease for this client, let it go. */
|
||||||
if (memcmp (packet ->
|
if (memcmp (packet ->
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER].data,
|
options [DHO_DHCP_SERVER_IDENTIFIER].data,
|
||||||
siaddr.iabuf, siaddr.len)) {
|
packet -> interface -> address.iabuf,
|
||||||
|
packet -> interface -> address.len)) {
|
||||||
if (lease)
|
if (lease)
|
||||||
release_lease (lease);
|
release_lease (lease);
|
||||||
return;
|
return;
|
||||||
@ -237,6 +238,7 @@ void nak_lease (packet, cip)
|
|||||||
struct dhcp_packet raw;
|
struct dhcp_packet raw;
|
||||||
unsigned char nak = DHCPNAK;
|
unsigned char nak = DHCPNAK;
|
||||||
struct packet outgoing;
|
struct packet outgoing;
|
||||||
|
struct hardware hto;
|
||||||
|
|
||||||
struct tree_cache *options [256];
|
struct tree_cache *options [256];
|
||||||
struct tree_cache dhcpnak_tree;
|
struct tree_cache dhcpnak_tree;
|
||||||
@ -272,7 +274,7 @@ void nak_lease (packet, cip)
|
|||||||
cons_options (packet, &outgoing, options, 0);
|
cons_options (packet, &outgoing, options, 0);
|
||||||
|
|
||||||
/* memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/
|
/* memset (&raw.ciaddr, 0, sizeof raw.ciaddr);*/
|
||||||
memcpy (&raw.siaddr, siaddr.iabuf, 4);
|
memcpy (&raw.siaddr, packet -> interface -> address.iabuf, 4);
|
||||||
raw.giaddr = packet -> raw -> giaddr;
|
raw.giaddr = packet -> raw -> giaddr;
|
||||||
memcpy (raw.chaddr, packet -> raw -> chaddr, sizeof raw.chaddr);
|
memcpy (raw.chaddr, packet -> raw -> chaddr, sizeof raw.chaddr);
|
||||||
raw.hlen = packet -> raw -> hlen;
|
raw.hlen = packet -> raw -> hlen;
|
||||||
@ -290,7 +292,7 @@ void nak_lease (packet, cip)
|
|||||||
to.sin_addr = raw.giaddr;
|
to.sin_addr = raw.giaddr;
|
||||||
to.sin_port = server_port;
|
to.sin_port = server_port;
|
||||||
} else {
|
} else {
|
||||||
memcpy (&to.sin_addr.s_addr, cip->iabuf, 4);
|
to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
|
||||||
to.sin_port = packet->client_port;
|
to.sin_port = packet->client_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,9 +308,14 @@ void nak_lease (packet, cip)
|
|||||||
packet -> raw -> chaddr),
|
packet -> raw -> chaddr),
|
||||||
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
||||||
|
|
||||||
|
hto.htype = packet -> raw -> htype;
|
||||||
|
hto.hlen = packet -> raw -> hlen;
|
||||||
|
memcpy (hto.haddr, packet -> raw -> chaddr, hto.hlen);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result = sendpkt (packet, &raw, outgoing.packet_length,
|
result = send_packet (packet -> interface,
|
||||||
(struct sockaddr *) &to, sizeof(to));
|
packet, &raw, outgoing.packet_length,
|
||||||
|
&to, (struct hardware *)0);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
warn ("sendpkt: %m");
|
warn ("sendpkt: %m");
|
||||||
|
|
||||||
@ -334,6 +341,7 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
struct dhcp_packet raw;
|
struct dhcp_packet raw;
|
||||||
struct tree_cache *options [256];
|
struct tree_cache *options [256];
|
||||||
struct sockaddr_in to;
|
struct sockaddr_in to;
|
||||||
|
struct hardware hto;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
struct tree_cache dhcpoffer_tree;
|
struct tree_cache dhcpoffer_tree;
|
||||||
@ -486,9 +494,12 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
options [DHO_DHCP_MESSAGE_TYPE] -> tree = (struct tree *)0;
|
options [DHO_DHCP_MESSAGE_TYPE] -> tree = (struct tree *)0;
|
||||||
|
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] = &server_id_tree;
|
options [DHO_DHCP_SERVER_IDENTIFIER] = &server_id_tree;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> value = siaddr.iabuf;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> value =
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> len = siaddr.len;
|
packet -> interface -> address.iabuf;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> buf_size = siaddr.len;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> len =
|
||||||
|
packet -> interface -> address.len;
|
||||||
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> buf_size =
|
||||||
|
packet -> interface -> address.len;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> timeout = 0xFFFFFFFF;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> timeout = 0xFFFFFFFF;
|
||||||
options [DHO_DHCP_SERVER_IDENTIFIER] -> tree = (struct tree *)0;
|
options [DHO_DHCP_SERVER_IDENTIFIER] -> tree = (struct tree *)0;
|
||||||
|
|
||||||
@ -541,7 +552,7 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
|
|
||||||
raw.ciaddr = packet -> raw -> ciaddr;
|
raw.ciaddr = packet -> raw -> ciaddr;
|
||||||
memcpy (&raw.yiaddr, lease -> ip_addr.iabuf, 4);
|
memcpy (&raw.yiaddr, lease -> ip_addr.iabuf, 4);
|
||||||
memcpy (&raw.siaddr, siaddr.iabuf, 4);
|
memcpy (&raw.siaddr, packet -> interface -> address.iabuf, 4);
|
||||||
raw.giaddr = packet -> raw -> giaddr;
|
raw.giaddr = packet -> raw -> giaddr;
|
||||||
|
|
||||||
raw.xid = packet -> raw -> xid;
|
raw.xid = packet -> raw -> xid;
|
||||||
@ -566,7 +577,7 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
|
|
||||||
/* Otherwise, broadcast it on the local network. */
|
/* Otherwise, broadcast it on the local network. */
|
||||||
} else {
|
} else {
|
||||||
memcpy (&to.sin_addr.s_addr, lease -> ip_addr.iabuf, 4);
|
to.sin_addr.s_addr = htonl (INADDR_BROADCAST);
|
||||||
to.sin_port = htons (ntohs (server_port) + 1); /* XXX */
|
to.sin_port = htons (ntohs (server_port) + 1); /* XXX */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,9 +594,13 @@ void ack_lease (packet, lease, offer, when)
|
|||||||
packet -> raw -> chaddr),
|
packet -> raw -> chaddr),
|
||||||
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
inet_ntoa (to.sin_addr), htons (to.sin_port));
|
||||||
|
|
||||||
errno = 0;
|
hto.htype = packet -> raw -> htype;
|
||||||
result = sendpkt (packet, &raw, outgoing.packet_length,
|
hto.hlen = packet -> raw -> hlen;
|
||||||
(struct sockaddr *) &to, sizeof(to));
|
memcpy (hto.haddr, packet -> raw -> chaddr, hto.hlen);
|
||||||
|
|
||||||
|
result = send_packet (packet -> interface,
|
||||||
|
packet, &raw, outgoing.packet_length,
|
||||||
|
&to, &hto);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
warn ("sendpkt: %m");
|
warn ("sendpkt: %m");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user