+ binding.sendp(resp)
+ except socket.error, e:
+ logging.warn(" - DHCP response on %s (%s) failed: %s",
+ binding.tap, binding.hostname, str(e))
+ except Exception, e:
+ logging.warn(" - Unkown error during DHCP response on %s (%s): %s",
+ binding.tap, binding.hostname, str(e))
+
+ def dhcpv6_response(self, arg1, arg2=None): # pylint: disable=W0613
+
+ logging.info(" * Processing pending DHCPv6 request")
+ # Workaround for supporting both squeezy's nfqueue-bindings-python
+ # and wheezy's python-nfqueue because for some reason the function's
+ # signature has changed and has broken compatibility
+ # See bug http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=718894
+ if arg2:
+ payload = arg2
+ else:
+ payload = arg1
+ pkt = IPv6(payload.get_data())
+ indev = get_indev(payload)
+
+ #TODO: figure out how to find the src mac
+ mac = None
+ binding = self.get_binding(indev, mac)
+ if binding is None:
+ # We don't know anything about this interface, so accept the packet
+ # and return
+ logging.debug(" - Ignoring dhcpv6 request for mac %s", mac)
+ # We don't know what to do with this packet, so let the kernel
+ # handle it
+ payload.set_verdict(nfqueue.NF_ACCEPT)
+ return
+
+ # Signal the kernel that it shouldn't further process the packet
+ payload.set_verdict(nfqueue.NF_DROP)
+
+ subnet = binding.net6
+
+ if subnet.net is None:
+ logging.debug(" - No IPv6 network assigned for tap %s", binding.tap)
+ return
+
+ indevmac = self.get_iface_hw_addr(binding.indev)
+ ifll = subnet.make_ll64(indevmac)
+ if ifll is None:
+ return
+
+ ofll = subnet.make_ll64(binding.mac)
+ if ofll is None:
+ return
+
+ logging.info(" - Generating DHCPv6 response for host %s (mac %s) on tap %s",
+ binding.hostname, binding.mac, binding.tap)
+
+ if self.dhcpv6_domains:
+ domains = self.dhcpv6_domains
+ else:
+ domains = [binding.hostname.split('.', 1)[-1]]
+
+ # We do this in order not to caclulate optlen ourselves
+ dnsdomains = str(DHCP6OptDNSDomains(dnsdomains=domains))
+ dnsservers = str(DHCP6OptDNSServers(dnsservers=self.ipv6_nameservers))
+
+ resp = Ether(src=indevmac, dst=binding.mac)/\
+ IPv6(tc=192, src=str(ifll), dst=str(ofll))/\
+ UDP(sport=pkt.dport, dport=pkt.sport)/\
+ DHCP6_Reply(trid=pkt[DHCP6_InfoRequest].trid)/\
+ DHCP6OptClientId(duid=pkt[DHCP6OptClientId].duid)/\
+ DHCP6OptServerId(duid=DUID_LLT(lladdr=indevmac, timeval=time.time()))/\
+ DHCP6OptDNSDomains(dnsdomains)/\
+ DHCP6OptDNSServers(dnsservers)
+
+ try:
+ binding.sendp(resp)