def test_dhcpv6_simple_relay_reply_foreign_option(self): pkt = DHCP6_RelayReply(peeraddr=self.tap_lladdr) / \ DHCP6OptIfaceId(ifaceid=self.node_ifaceid) / \ DHCP6OptClientId() / \ DHCP6OptRelayMsg(message=DHCP6_Reply(trid=self.test_trid)) result = self.send_and_exp_pkts(pkt, DHCP6_Reply, client=False) self.assert_len(result, 1) pkt = result[0] self.assert_relayed_reply_pkt_w_trid(pkt, DHCP6_Reply) self.assert_node_responsive()
def send_DHCPv6_Reply(self, pkt): """ Sends out the DHCPv6 Reply message. """ header = self.build_reply_headers(pkt) trid = pkt[DHCP6_InfoRequest].trid srv_duid = header[Ether].src cli_id = DHCP6OptClientId(duid=pkt[DHCP6OptClientId].duid) srv_id = DHCP6OptServerId(duid=DUID_LL(lladdr=srv_duid)) sendp( header / DHCP6_Reply(trid=trid) / cli_id / srv_id, iface=self.iface, verbose=False, )
def testfunc(child): iface = os.environ["TAP"] pkt = wait_for_dhcpv6_pkt(iface) # the packet was a solicit assert DHCP6_Solicit in pkt # check if the sender is the upstream interface of the node upstream_netif = get_upstream_netif(child) print(upstream_netif) upstream_hwaddrs = get_hwaddrs(child, upstream_netif) assert DHCP6OptClientId in pkt and DUID_LL in pkt[DHCP6OptClientId].duid assert pkt[DHCP6OptClientId].duid[DUID_LL].lladdr in upstream_hwaddrs # and it is asking for a prefix delegation assert DHCP6OptIA_PD in pkt # reply to solicit with advertise and a prefix provided trid = pkt[DHCP6_Solicit].trid srv_duid = "aa:bb:cc:dd:ee:ff" cli_id = DHCP6OptClientId(duid=pkt[DHCP6OptClientId].duid) srv_id = DHCP6OptServerId(duid=DUID_LL(lladdr=srv_duid)) prefix = "2001:db8:{:x}:{:x}::".format(random.randint(0, 0xffff), random.randint(0, 0xffff)) ia_pd = DHCP6OptIA_PD(T1=12000, T2=13000, iaid=pkt[DHCP6OptIA_PD].iaid, iapdopt=[ DHCP6OptIAPrefix(preflft=14000, validlft=15000, prefix=prefix, plen=64) ]) # start sniffer to catch incoming request sniffer = start_sniffer(iface, stop_filter=lambda pkt: DHCP6_Request in pkt) sendp(build_reply_headers(pkt) / DHCP6_Advertise(trid=trid) / cli_id / srv_id / ia_pd, iface=iface, verbose=False) # wait for request pkt = wait_for_dhcpv6_pkt(iface, sniffer) # the packet was indeed a request assert DHCP6_Request in pkt # and from the client assert DHCP6OptClientId in pkt and DUID_LL in pkt[DHCP6OptClientId].duid assert pkt[DHCP6OptClientId].duid[DUID_LL].lladdr in upstream_hwaddrs # and it is trying to talk to this server assert DHCP6OptServerId in pkt and DUID_LL in pkt[DHCP6OptServerId].duid assert pkt[DHCP6OptServerId].duid[DUID_LL].lladdr == srv_duid # and is still asking for a prefix delegation assert DHCP6OptIA_PD in pkt # reply to request with reply and a prefix provided trid = pkt[DHCP6_Request].trid sendp(build_reply_headers(pkt) / DHCP6_Reply(trid=trid) / cli_id / srv_id / ia_pd, iface=iface, verbose=False) time.sleep(1) # check if global address was configured child.sendline("ifconfig {}".format(get_downstream_netif(child))) # remove one trailing ':' from prefix just to be safe ;-) child.expect(r"inet6 addr:\s+{}[0-9a-fA-F:]+\s".format(prefix[:-1])) print("SUCCESS")
def test_dhcpv6_relay_reply_no_ifaceid_no_linkaddr(self): pkt = DHCP6_RelayReply(peeraddr=self.tap_lladdr) / \ DHCP6OptRelayMsg(message=DHCP6_Reply(trid=self.test_trid)) self.assert_pkt_ignored(pkt, client_pkt=False)
def test_dhcpv6_relay_reply_invalid_optlen(self): pkt = DHCP6_RelayReply(peeraddr=self.tap_lladdr) / \ DHCP6OptIfaceId(ifaceid=self.node_ifaceid) / \ DHCP6OptRelayMsg(optlen=32, message=DHCP6_Reply(trid=self.test_trid)) self.assert_pkt_ignored(pkt, client_pkt=False)
def test_dhcpv6_relay_reply_unexpected_peeraddr(self): pkt = DHCP6_RelayReply(peeraddr="fe80::abcd:f00:1337") / \ DHCP6OptIfaceId(ifaceid=self.node_ifaceid) / \ DHCP6OptRelayMsg(message=DHCP6_Reply(trid=self.test_trid)) self.assert_pkt_ignored(pkt, client_pkt=False)
def test_dhcpv6_relay_reply_unexpected_ifaceid(self): pkt = DHCP6_RelayReply(peeraddr=self.tap_lladdr) / \ DHCP6OptIfaceId(ifaceid=b"ab") / \ DHCP6OptRelayMsg(message=DHCP6_Reply(trid=self.test_trid)) self.assert_pkt_ignored(pkt, client_pkt=False)
def test_dhcpv6_simple_relay_reply_foreign_option_w_bogus_optlen(self): pkt = DHCP6_RelayReply(peeraddr=self.tap_lladdr) / \ DHCP6OptIfaceId(ifaceid=self.node_ifaceid) / \ DHCP6OptRelayMsg(message=DHCP6_Reply(trid=self.test_trid)) / \ DHCP6OptClientId(optlen=32) self.assert_pkt_ignored(pkt, client_pkt=False)
def test_dhcpv6_simple_relay_reply_options_reversed(self): pkt = DHCP6_RelayReply(peeraddr=self.tap_lladdr) / \ DHCP6OptRelayMsg(message=DHCP6_Reply(trid=self.test_trid)) / \ DHCP6OptIfaceId(ifaceid=self.node_ifaceid) self._test_dhcpv6_simple_relay_reply(pkt, DHCP6_Reply)