1 diff -up dhcp-4.2.2/client/dhclient.c.lpf-ib dhcp-4.2.2/client/dhclient.c
2 --- dhcp-4.2.2/client/dhclient.c.lpf-ib 2011-09-19 11:24:08.693775799 +0200
3 +++ dhcp-4.2.2/client/dhclient.c 2011-09-19 11:24:08.703775541 +0200
4 @@ -113,6 +113,8 @@ static int check_domain_name_list(const
5 static int check_option_values(struct universe *universe, unsigned int opt,
6 const char *ptr, size_t len);
8 +static void setup_ib_interface(struct interface_info *ip);
11 main(int argc, char **argv) {
13 @@ -919,6 +921,14 @@ main(int argc, char **argv) {
15 srandom(seed + cur_time + (unsigned)getpid());
17 + /* Setup specific Infiniband options */
18 + for (ip = interfaces; ip; ip = ip->next) {
20 + (ip->hw_address.hbuf[0] == HTYPE_INFINIBAND)) {
21 + setup_ib_interface(ip);
25 /* Start a configuration state machine for each interface. */
27 if (local_family == AF_INET6) {
28 @@ -1195,6 +1205,29 @@ int find_subnet (struct subnet **sp,
32 +static void setup_ib_interface(struct interface_info *ip)
36 + /* Set the broadcast flag */
37 + ip->client->config->bootp_broadcast_always = 1;
40 + * Find out if a dhcp-client-identifier option was specified either
41 + * in the config file or on the command line
43 + for (g = ip->client->config->on_transmission; g != NULL; g = g->next) {
44 + if ((g->statements != NULL) &&
45 + (strcmp(g->statements->data.option->option->name,
46 + "dhcp-client-identifier") == 0)) {
51 + /* No client ID specified */
52 + log_fatal("dhcp-client-identifier must be specified for InfiniBand");
57 * Each routine is called from the dhclient_state_machine() in one of
58 diff -up dhcp-4.2.2/common/bpf.c.lpf-ib dhcp-4.2.2/common/bpf.c
59 --- dhcp-4.2.2/common/bpf.c.lpf-ib 2011-09-19 11:24:08.694775773 +0200
60 +++ dhcp-4.2.2/common/bpf.c 2011-09-19 11:24:08.704775516 +0200
61 @@ -198,11 +198,44 @@ struct bpf_insn dhcp_bpf_filter [] = {
62 BPF_STMT(BPF_RET+BPF_K, 0),
65 +/* Packet filter program for DHCP over Infiniband.
68 + * Changes to the filter program may require changes to the constant offsets
69 + * used in lpf_gen_filter_setup to patch the port in the BPF program!
72 +struct bpf_insn dhcp_ib_bpf_filter [] = {
73 + /* Packet filter for Infiniband */
74 + /* Make sure it's a UDP packet... */
75 + BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 9),
76 + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6),
78 + /* Make sure this isn't a fragment... */
79 + BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 6),
80 + BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 4, 0),
82 + /* Get the IP header length... */
83 + BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 0),
85 + /* Make sure it's to the right port... */
86 + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 2),
87 + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
89 + /* If we passed all the tests, ask for the whole packet. */
90 + BPF_STMT(BPF_RET + BPF_K, (u_int)-1),
92 + /* Otherwise, drop it. */
93 + BPF_STMT(BPF_RET + BPF_K, 0),
96 #if defined (DEC_FDDI)
97 struct bpf_insn *bpf_fddi_filter;
100 int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn);
101 +int dhcp_ib_bpf_filter_len = sizeof dhcp_ib_bpf_filter / sizeof (struct bpf_insn);
103 #if defined (HAVE_TR_SUPPORT)
104 struct bpf_insn dhcp_bpf_tr_filter [] = {
105 /* accept all token ring packets due to variable length header */
106 diff -up dhcp-4.2.2/common/lpf.c.lpf-ib dhcp-4.2.2/common/lpf.c
107 --- dhcp-4.2.2/common/lpf.c.lpf-ib 2011-09-19 11:24:08.694775773 +0200
108 +++ dhcp-4.2.2/common/lpf.c 2011-09-19 11:26:15.107109935 +0200
110 #include "includes/netinet/udp.h"
111 #include "includes/netinet/if_ether.h"
113 +#include <ifaddrs.h>
115 #ifndef PACKET_AUXDATA
116 #define PACKET_AUXDATA 8
117 @@ -59,6 +60,15 @@ struct tpacket_auxdata
118 /* Reinitializes the specified interface after an address change. This
119 is not required for packet-filter APIs. */
121 +/* Default broadcast address for IPoIB */
122 +static unsigned char default_ib_bcast_addr[20] = {
123 + 0x00, 0xff, 0xff, 0xff,
124 + 0xff, 0x12, 0x40, 0x1b,
125 + 0x00, 0x00, 0x00, 0x00,
126 + 0x00, 0x00, 0x00, 0x00,
127 + 0xff, 0xff, 0xff, 0xff
131 void if_reinitialize_send (info)
132 struct interface_info *info;
133 @@ -86,10 +96,21 @@ int if_register_lpf (info)
134 struct sockaddr common;
140 /* Make an LPF socket. */
141 - if ((sock = socket(PF_PACKET, SOCK_RAW,
142 - htons((short)ETH_P_ALL))) < 0) {
145 + if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
147 + protocol = ETHERTYPE_IP;
150 + protocol = ETH_P_ALL;
153 + if ((sock = socket(PF_PACKET, type, htons((short)protocol))) < 0) {
154 if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
155 errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
156 errno == EAFNOSUPPORT || errno == EINVAL) {
157 @@ -112,6 +133,7 @@ int if_register_lpf (info)
158 /* Bind to the interface name */
159 memset (&sa, 0, sizeof sa);
160 sa.ll.sll_family = AF_PACKET;
161 + sa.ll.sll_protocol = htons(protocol);
162 sa.ll.sll_ifindex = ifr.ifr_ifindex;
163 if (bind (sock, &sa.common, sizeof sa)) {
164 if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
165 @@ -127,8 +149,6 @@ int if_register_lpf (info)
166 log_fatal ("Bind socket to interface: %m");
169 - get_hw_addr(info->name, &info->hw_address);
173 #endif /* USE_LPF_SEND || USE_LPF_RECEIVE */
174 @@ -183,6 +203,8 @@ void if_deregister_send (info)
175 in bpf includes... */
176 extern struct sock_filter dhcp_bpf_filter [];
177 extern int dhcp_bpf_filter_len;
178 +extern struct sock_filter dhcp_ib_bpf_filter [];
179 +extern int dhcp_ib_bpf_filter_len;
181 #if defined (HAVE_TR_SUPPORT)
182 extern struct sock_filter dhcp_bpf_tr_filter [];
183 @@ -200,11 +222,13 @@ void if_register_receive (info)
184 /* Open a LPF device and hang it on this interface... */
185 info -> rfdesc = if_register_lpf (info);
188 - if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA, &val,
190 - if (errno != ENOPROTOOPT)
191 - log_fatal ("Failed to set auxiliary packet data: %m");
192 + if (info->hw_address.hbuf[0] != HTYPE_INFINIBAND) {
194 + if (setsockopt (info -> rfdesc, SOL_PACKET, PACKET_AUXDATA,
195 + &val, sizeof val) < 0) {
196 + if (errno != ENOPROTOOPT)
197 + log_fatal ("Failed to set auxiliary packet data: %m");
201 #if defined (HAVE_TR_SUPPORT)
202 @@ -250,15 +274,28 @@ static void lpf_gen_filter_setup (info)
204 memset(&p, 0, sizeof(p));
206 - /* Set up the bpf filter program structure. This is defined in
208 - p.len = dhcp_bpf_filter_len;
209 - p.filter = dhcp_bpf_filter;
211 - /* Patch the server port into the LPF program...
212 - XXX changes to filter program may require changes
213 - to the insn number(s) used below! XXX */
214 - dhcp_bpf_filter [8].k = ntohs ((short)local_port);
215 + if (info->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
216 + /* Set up the bpf filter program structure. */
217 + p.len = dhcp_ib_bpf_filter_len;
218 + p.filter = dhcp_ib_bpf_filter;
220 + /* Patch the server port into the LPF program...
222 + changes to filter program may require changes
223 + to the insn number(s) used below!
225 + dhcp_ib_bpf_filter[6].k = ntohs ((short)local_port);
227 + /* Set up the bpf filter program structure.
228 + This is defined in bpf.c */
229 + p.len = dhcp_bpf_filter_len;
230 + p.filter = dhcp_bpf_filter;
232 + /* Patch the server port into the LPF program...
233 + XXX changes to filter program may require changes
234 + to the insn number(s) used below! XXX */
235 + dhcp_bpf_filter [8].k = ntohs ((short)local_port);
238 if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
240 @@ -315,6 +352,54 @@ static void lpf_tr_filter_setup (info)
241 #endif /* USE_LPF_RECEIVE */
244 +ssize_t send_packet_ib(interface, packet, raw, len, from, to, hto)
245 + struct interface_info *interface;
246 + struct packet *packet;
247 + struct dhcp_packet *raw;
249 + struct in_addr from;
250 + struct sockaddr_in *to;
251 + struct hardware *hto;
253 + unsigned ibufp = 0;
254 + double ih [1536 / sizeof (double)];
255 + unsigned char *buf = (unsigned char *)ih;
259 + struct sockaddr sa;
260 + struct sockaddr_ll sll;
261 + struct sockaddr_storage ss;
264 + assemble_udp_ip_header (interface, buf, &ibufp, from.s_addr,
265 + to->sin_addr.s_addr, to->sin_port,
266 + (unsigned char *)raw, len);
267 + memcpy (buf + ibufp, raw, len);
269 + memset(&su, 0, sizeof(su));
270 + su.sll.sll_family = AF_PACKET;
271 + su.sll.sll_protocol = htons(ETHERTYPE_IP);
273 + if (!(su.sll.sll_ifindex = if_nametoindex(interface->name))) {
275 + log_error ("send_packet_ib: %m - failed to get if index");
279 + su.sll.sll_hatype = htons(HTYPE_INFINIBAND);
280 + su.sll.sll_halen = sizeof(interface->bcast_addr);
281 + memcpy(&su.sll.sll_addr, interface->bcast_addr, 20);
283 + result = sendto(interface->wfdesc, buf, ibufp + len, 0,
284 + &su.sa, sizeof(su));
287 + log_error ("send_packet_ib: %m");
292 ssize_t send_packet (interface, packet, raw, len, from, to, hto)
293 struct interface_info *interface;
294 struct packet *packet;
295 @@ -335,6 +420,11 @@ ssize_t send_packet (interface, packet,
296 return send_fallback (interface, packet, raw,
299 + if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
300 + return send_packet_ib(interface, packet, raw, len, from,
304 if (hto == NULL && interface->anycast_mac_addr.hlen)
305 hto = &interface->anycast_mac_addr;
307 @@ -356,6 +446,42 @@ ssize_t send_packet (interface, packet,
308 #endif /* USE_LPF_SEND */
310 #ifdef USE_LPF_RECEIVE
311 +ssize_t receive_packet_ib (interface, buf, len, from, hfrom)
312 + struct interface_info *interface;
313 + unsigned char *buf;
315 + struct sockaddr_in *from;
316 + struct hardware *hfrom;
320 + unsigned char ibuf [1536];
321 + unsigned bufix = 0;
324 + length = read(interface->rfdesc, ibuf, sizeof(ibuf));
329 + offset = decode_udp_ip_header(interface, ibuf, bufix, from,
330 + (unsigned)length, &paylen, 0);
338 + if (length < paylen)
339 + log_fatal("Internal inconsistency at %s:%d.", MDL);
341 + /* Copy out the data in the packet... */
342 + memcpy(buf, &ibuf[bufix], paylen);
344 + return (ssize_t)paylen;
347 ssize_t receive_packet (interface, buf, len, from, hfrom)
348 struct interface_info *interface;
350 @@ -382,6 +508,10 @@ ssize_t receive_packet (interface, buf,
352 struct cmsghdr *cmsg;
354 + if (interface->hw_address.hbuf[0] == HTYPE_INFINIBAND) {
355 + return receive_packet_ib(interface, buf, len, from, hfrom);
358 length = recvmsg (interface -> rfdesc, &msg, 0);
361 @@ -462,33 +592,44 @@ void maybe_setup_fallback ()
365 -get_hw_addr(const char *name, struct hardware *hw) {
368 - struct sockaddr *sa;
369 +get_hw_addr(struct interface_info *info)
371 + struct hardware *hw = &info->hw_address;
372 + char *name = info->name;
373 + struct ifaddrs *ifaddrs;
374 + struct ifaddrs *ifa;
375 + struct sockaddr_ll *sll = NULL;
377 - if (strlen(name) >= sizeof(tmp.ifr_name)) {
378 - log_fatal("Device name too long: \"%s\"", name);
380 + if (getifaddrs(&ifaddrs) == -1)
381 + log_fatal("Failed to get interfaces");
383 - sock = socket(AF_INET, SOCK_DGRAM, 0);
385 - log_fatal("Can't create socket for \"%s\": %m", name);
386 + for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
388 + if (ifa->ifa_addr == NULL)
391 + if (ifa->ifa_addr->sa_family != AF_PACKET)
394 + if (ifa->ifa_flags & IFF_LOOPBACK)
397 + if (strcmp(ifa->ifa_name, name) == 0) {
398 + sll = (struct sockaddr_ll *)(void *)ifa->ifa_addr;
403 - memset(&tmp, 0, sizeof(tmp));
404 - strcpy(tmp.ifr_name, name);
405 - if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
406 - log_fatal("Error getting hardware address for \"%s\": %m",
409 + freeifaddrs(ifaddrs);
410 + log_fatal("Failed to get HW address for %s\n", name);
413 - sa = &tmp.ifr_hwaddr;
414 - switch (sa->sa_family) {
415 + switch (sll->sll_hatype) {
418 hw->hbuf[0] = HTYPE_ETHER;
419 - memcpy(&hw->hbuf[1], sa->sa_data, 6);
420 + memcpy(&hw->hbuf[1], sll->sll_addr, 6);
423 #ifdef ARPHRD_IEEE802_TR
424 @@ -496,18 +637,35 @@ get_hw_addr(const char *name, struct har
425 #endif /* ARPHRD_IEEE802_TR */
427 hw->hbuf[0] = HTYPE_IEEE802;
428 - memcpy(&hw->hbuf[1], sa->sa_data, 6);
429 + memcpy(&hw->hbuf[1], sll->sll_addr, 6);
433 hw->hbuf[0] = HTYPE_FDDI;
434 - memcpy(&hw->hbuf[1], sa->sa_data, 16);
435 + memcpy(&hw->hbuf[1], sll->sll_addr, 16);
437 + case ARPHRD_INFINIBAND:
438 + /* For Infiniband, save the broadcast address and store
439 + * the port GUID into the hardware address.
441 + if (ifa->ifa_flags & IFF_BROADCAST) {
442 + struct sockaddr_ll *bll;
444 + bll = (struct sockaddr_ll *)ifa->ifa_broadaddr;
445 + memcpy(&info->bcast_addr, bll->sll_addr, 20);
447 + memcpy(&info->bcast_addr, default_ib_bcast_addr,
452 + hw->hbuf[0] = HTYPE_INFINIBAND;
454 #if defined(ARPHRD_PPP)
456 if (local_family != AF_INET6)
457 - log_fatal("Unsupported device type %d for \"%s\"",
458 - sa->sa_family, name);
459 + log_fatal("Unsupported device type %ld for \"%s\"",
460 + (long int)sll->sll_family, name);
462 hw->hbuf[0] = HTYPE_RESERVED;
463 /* 0xdeadbeef should never occur on the wire,
464 @@ -520,10 +678,11 @@ get_hw_addr(const char *name, struct har
468 + freeifaddrs(ifaddrs);
469 log_fatal("Unsupported device type %ld for \"%s\"",
470 - (long int)sa->sa_family, name);
471 + (long int)sll->sll_family, name);
475 + freeifaddrs(ifaddrs);
478 diff -up dhcp-4.2.2/common/socket.c.lpf-ib dhcp-4.2.2/common/socket.c
479 --- dhcp-4.2.2/common/socket.c.lpf-ib 2011-06-27 18:18:20.000000000 +0200
480 +++ dhcp-4.2.2/common/socket.c 2011-09-19 11:24:08.705775490 +0200
481 @@ -324,7 +324,7 @@ void if_register_send (info)
482 info->wfdesc = if_register_socket(info, AF_INET, 0);
483 /* If this is a normal IPv4 address, get the hardware address. */
484 if (strcmp(info->name, "fallback") != 0)
485 - get_hw_addr(info->name, &info->hw_address);
487 #if defined (USE_SOCKET_FALLBACK)
488 /* Fallback only registers for send, but may need to receive as
490 @@ -387,7 +387,7 @@ void if_register_receive (info)
491 #endif /* IP_PKTINFO... */
492 /* If this is a normal IPv4 address, get the hardware address. */
493 if (strcmp(info->name, "fallback") != 0)
494 - get_hw_addr(info->name, &info->hw_address);
497 if (!quiet_interface_discovery)
498 log_info ("Listening on Socket/%s%s%s",
499 @@ -497,7 +497,7 @@ if_register6(struct interface_info *info
501 if_register_multicast(info);
503 - get_hw_addr(info->name, &info->hw_address);
506 if (!quiet_interface_discovery) {
507 if (info->shared_network != NULL) {
508 diff -up dhcp-4.2.2/includes/dhcpd.h.lpf-ib dhcp-4.2.2/includes/dhcpd.h
509 --- dhcp-4.2.2/includes/dhcpd.h.lpf-ib 2011-09-19 11:24:08.696775721 +0200
510 +++ dhcp-4.2.2/includes/dhcpd.h 2011-09-19 11:24:08.707775438 +0200
511 @@ -1243,6 +1243,7 @@ struct interface_info {
512 struct shared_network *shared_network;
513 /* Networks connected to this interface. */
514 struct hardware hw_address; /* Its physical address. */
515 + u_int8_t bcast_addr[20]; /* Infiniband broadcast address */
516 struct in_addr *addresses; /* Addresses associated with this
519 @@ -2356,7 +2357,7 @@ void print_dns_status (int, struct dhcp_
521 const char *print_time(TIME);
523 -void get_hw_addr(const char *name, struct hardware *hw);
524 +void get_hw_addr(struct interface_info *info);
527 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \
528 diff -up dhcp-4.2.2/includes/dhcp.h.lpf-ib dhcp-4.2.2/includes/dhcp.h
529 --- dhcp-4.2.2/includes/dhcp.h.lpf-ib 2011-09-19 11:24:08.696775721 +0200
530 +++ dhcp-4.2.2/includes/dhcp.h 2011-09-19 11:24:08.707775438 +0200
531 @@ -79,6 +79,7 @@ struct dhcp_packet {
532 #define HTYPE_ETHER 1 /* Ethernet 10Mbps */
533 #define HTYPE_IEEE802 6 /* IEEE 802.2 Token Ring... */
534 #define HTYPE_FDDI 8 /* FDDI... */
535 +#define HTYPE_INFINIBAND 32 /* Infiniband IPoIB */
537 #define HTYPE_RESERVED 0 /* RFC 5494 */