1 diff -up dhcp-4.2.4-P2/client/dhclient.c.lpf-ib dhcp-4.2.4-P2/client/dhclient.c
2 --- dhcp-4.2.4-P2/client/dhclient.c.lpf-ib 2012-11-30 14:05:07.399394154 +0100
3 +++ dhcp-4.2.4-P2/client/dhclient.c 2012-11-30 14:05:07.406394070 +0100
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 @@ -909,6 +911,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 @@ -1185,6 +1195,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.4-P2/common/bpf.c.lpf-ib dhcp-4.2.4-P2/common/bpf.c
59 --- dhcp-4.2.4-P2/common/bpf.c.lpf-ib 2012-11-30 14:05:07.394394214 +0100
60 +++ dhcp-4.2.4-P2/common/bpf.c 2012-11-30 14:05:07.407394058 +0100
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.4-P2/common/lpf.c.lpf-ib dhcp-4.2.4-P2/common/lpf.c
107 --- dhcp-4.2.4-P2/common/lpf.c.lpf-ib 2012-11-30 14:05:07.394394214 +0100
108 +++ dhcp-4.2.4-P2/common/lpf.c 2012-11-30 14:19:27.211031532 +0100
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 @@ -461,11 +591,32 @@ void maybe_setup_fallback ()
366 -get_hw_addr(const char *name, struct hardware *hw) {
367 +struct sockaddr_ll *
368 +get_ll (struct ifaddrs *ifaddrs, struct ifaddrs **ifa, char *name)
370 + for (*ifa = ifaddrs; *ifa != NULL; *ifa = (*ifa)->ifa_next) {
371 + if ((*ifa)->ifa_addr == NULL)
374 + if ((*ifa)->ifa_addr->sa_family != AF_PACKET)
377 + if ((*ifa)->ifa_flags & IFF_LOOPBACK)
380 + if (strcmp((*ifa)->ifa_name, name) == 0)
381 + return (struct sockaddr_ll *)(void *)(*ifa)->ifa_addr;
386 +struct sockaddr_ll *
387 +ioctl_get_ll(char *name)
391 - struct sockaddr *sa;
392 + struct sockaddr *sa = NULL;
393 + struct sockaddr_ll *sll = NULL;
395 if (strlen(name) >= sizeof(tmp.ifr_name)) {
396 log_fatal("Device name too long: \"%s\"", name);
397 @@ -479,16 +630,52 @@ get_hw_addr(const char *name, struct har
398 memset(&tmp, 0, sizeof(tmp));
399 strcpy(tmp.ifr_name, name);
400 if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
401 - log_fatal("Error getting hardware address for \"%s\": %m",
402 + log_fatal("Error getting hardware address for \"%s\": %m",
407 sa = &tmp.ifr_hwaddr;
408 - switch (sa->sa_family) {
409 + // needs to be freed outside this function
410 + sll = dmalloc (sizeof (struct sockaddr_ll), MDL);
412 + log_fatal("Unable to allocate memory for link layer address");
413 + memcpy(&sll->sll_hatype, &sa->sa_family, sizeof (sll->sll_hatype));
414 + memcpy(sll->sll_addr, sa->sa_data, sizeof (sll->sll_addr));
419 +get_hw_addr(struct interface_info *info)
421 + struct hardware *hw = &info->hw_address;
422 + char *name = info->name;
423 + struct ifaddrs *ifaddrs = NULL;
424 + struct ifaddrs *ifa = NULL;
425 + struct sockaddr_ll *sll = NULL;
426 + int sll_allocated = 0;
428 + if (getifaddrs(&ifaddrs) == -1)
429 + log_fatal("Failed to get interfaces");
431 + if ((sll = get_ll(ifaddrs, &ifa, name)) == NULL) {
433 + * We were unable to get link-layer address for name.
434 + * Fall back to ioctl(SIOCGIFHWADDR).
436 + sll = ioctl_get_ll(name);
440 + // shouldn't happed
441 + log_fatal("Unexpected internal error");
444 + switch (sll->sll_hatype) {
447 hw->hbuf[0] = HTYPE_ETHER;
448 - memcpy(&hw->hbuf[1], sa->sa_data, 6);
449 + memcpy(&hw->hbuf[1], sll->sll_addr, 6);
452 #ifdef ARPHRD_IEEE802_TR
453 @@ -496,18 +683,35 @@ get_hw_addr(const char *name, struct har
454 #endif /* ARPHRD_IEEE802_TR */
456 hw->hbuf[0] = HTYPE_IEEE802;
457 - memcpy(&hw->hbuf[1], sa->sa_data, 6);
458 + memcpy(&hw->hbuf[1], sll->sll_addr, 6);
462 hw->hbuf[0] = HTYPE_FDDI;
463 - memcpy(&hw->hbuf[1], sa->sa_data, 6);
464 + memcpy(&hw->hbuf[1], sll->sll_addr, 6);
466 + case ARPHRD_INFINIBAND:
467 + /* For Infiniband, save the broadcast address and store
468 + * the port GUID into the hardware address.
470 + if (ifa->ifa_flags & IFF_BROADCAST) {
471 + struct sockaddr_ll *bll;
473 + bll = (struct sockaddr_ll *)ifa->ifa_broadaddr;
474 + memcpy(&info->bcast_addr, bll->sll_addr, 20);
476 + memcpy(&info->bcast_addr, default_ib_bcast_addr,
481 + hw->hbuf[0] = HTYPE_INFINIBAND;
483 #if defined(ARPHRD_PPP)
485 if (local_family != AF_INET6)
486 - log_fatal("Unsupported device type %d for \"%s\"",
487 - sa->sa_family, name);
488 + log_fatal("local_family != AF_INET6 for \"%s\"",
491 hw->hbuf[0] = HTYPE_RESERVED;
492 /* 0xdeadbeef should never occur on the wire,
493 @@ -520,10 +724,13 @@ get_hw_addr(const char *name, struct har
497 - log_fatal("Unsupported device type %ld for \"%s\"",
498 - (long int)sa->sa_family, name);
499 + freeifaddrs(ifaddrs);
500 + log_fatal("Unsupported device type %h for \"%s\"",
501 + sll->sll_hatype, name);
507 + freeifaddrs(ifaddrs);
510 diff -up dhcp-4.2.4-P2/common/socket.c.lpf-ib dhcp-4.2.4-P2/common/socket.c
511 --- dhcp-4.2.4-P2/common/socket.c.lpf-ib 2012-08-24 21:11:21.000000000 +0200
512 +++ dhcp-4.2.4-P2/common/socket.c 2012-11-30 14:05:07.408394046 +0100
513 @@ -325,7 +325,7 @@ void if_register_send (info)
514 info->wfdesc = if_register_socket(info, AF_INET, 0);
515 /* If this is a normal IPv4 address, get the hardware address. */
516 if (strcmp(info->name, "fallback") != 0)
517 - get_hw_addr(info->name, &info->hw_address);
519 #if defined (USE_SOCKET_FALLBACK)
520 /* Fallback only registers for send, but may need to receive as
522 @@ -388,7 +388,7 @@ void if_register_receive (info)
523 #endif /* IP_PKTINFO... */
524 /* If this is a normal IPv4 address, get the hardware address. */
525 if (strcmp(info->name, "fallback") != 0)
526 - get_hw_addr(info->name, &info->hw_address);
529 if (!quiet_interface_discovery)
530 log_info ("Listening on Socket/%s%s%s",
531 @@ -498,7 +498,7 @@ if_register6(struct interface_info *info
533 if_register_multicast(info);
535 - get_hw_addr(info->name, &info->hw_address);
538 if (!quiet_interface_discovery) {
539 if (info->shared_network != NULL) {
540 diff -up dhcp-4.2.4-P2/includes/dhcpd.h.lpf-ib dhcp-4.2.4-P2/includes/dhcpd.h
541 --- dhcp-4.2.4-P2/includes/dhcpd.h.lpf-ib 2012-11-30 14:05:07.400394142 +0100
542 +++ dhcp-4.2.4-P2/includes/dhcpd.h 2012-11-30 14:05:07.409394034 +0100
543 @@ -1249,6 +1249,7 @@ struct interface_info {
544 struct shared_network *shared_network;
545 /* Networks connected to this interface. */
546 struct hardware hw_address; /* Its physical address. */
547 + u_int8_t bcast_addr[20]; /* Infiniband broadcast address */
548 struct in_addr *addresses; /* Addresses associated with this
551 @@ -2368,7 +2369,7 @@ void print_dns_status (int, struct dhcp_
553 const char *print_time(TIME);
555 -void get_hw_addr(const char *name, struct hardware *hw);
556 +void get_hw_addr(struct interface_info *info);
559 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \