Browse Source

[2893] Configure the address family of the BPF program for lo interface.

Marcin Siodelski 10 years ago
parent
commit
36116b3f59
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/lib/dhcp/pkt_filter_bpf.cc

+ 8 - 2
src/lib/dhcp/pkt_filter_bpf.cc

@@ -110,9 +110,10 @@ struct bpf_insn ethernet_ip_udp_filter [] = {
 struct bpf_insn loopback_ip_udp_filter [] = {
     // Make sure this is an IP packet. The pseudo header comprises a 4-byte
     // long value identifying the address family, which should be set to
-    // AF_INET.
+    // AF_INET. The default value used here (0xFFFFFFFF) must be overriden
+    // with htonl(AF_INET) from within the openSocket function.
     BPF_STMT(BPF_LD + BPF_W + BPF_ABS, 0),
-    BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, htonl(AF_INET), 0, 8),
+    BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0xFFFFFFFF, 0, 8),
 
     // Make sure it's a UDP packet.  The IP protocol is at offset
     // 9 in the IP header so, adding the pseudo header size 4 bytes
@@ -257,6 +258,11 @@ PktFilterBPF::openSocket(Iface& iface,
     if (iface.flag_loopback_) {
         prog.bf_insns = loopback_ip_udp_filter;
         prog.bf_len = sizeof(loopback_ip_udp_filter) / sizeof(struct bpf_insn);
+        // The address family is AF_INET. It can't be hardcoded in the BPF program
+        // because we need to make the host to network order conversion using htonl
+        // and conversion can't be done within the BPF program structure as it
+        // doesn't work on some systems.
+        prog.bf_insns[1].k = htonl(AF_INET);
 
     } else {
         prog.bf_insns = ethernet_ip_udp_filter;