1
1
import fire
2
2
import os
3
- from scapy .all import sniff , sendp , Ether , IPv6 , ICMPv6ND_NS , ICMPv6ND_NA , ICMPv6NDOptDstLLAddr
3
+ from scapy .all import sniff , sendp , Ether , IPv6 , ICMPv6ND_NS , ICMPv6ND_NA , ICMPv6NDOptDstLLAddr , get_if_hwaddr
4
4
5
- is_strict_match = "STRICT" in os .environ
6
5
ns_counter = 0
7
6
def dump_nd_so (x ):
8
7
global ns_counter
@@ -22,21 +21,16 @@ def send_nd_ad_for(x, outer_ether_addr):
22
21
sendp (Ether (dst = ether_dst , src = ether_src )/ IPv6 (version = 6 , tc = 0 , fl = 0 , plen = 32 , hlim = 255 , src = x [ICMPv6ND_NS ].tgt , dst = x [IPv6 ].src )/ ICMPv6ND_NA (code = 0 , R = 0 , S = 1 , O = 1 , res = 0x0 , tgt = x [ICMPv6ND_NS ].tgt )/ ICMPv6NDOptDstLLAddr (type = 2 , len = 1 , lladdr = outer_ether_addr ), iface = iface )
23
22
return True
24
23
25
- def is_expected_nd_so (x , expected_prefix , router_ether_addr ):
26
- if is_strict_match :
27
- return x [Ether ].src == router_ether_addr and x [ICMPv6ND_NS ].tgt .startswith (expected_prefix )
28
- else :
29
- return x [ICMPv6ND_NS ].tgt .startswith (expected_prefix )
24
+ def is_expected_nd_so (x , expected_prefix ):
25
+ return x [ICMPv6ND_NS ].tgt .startswith (expected_prefix )
30
26
31
- def is_expected_nd_ad (x , expected_prefix , router_ether_addr ):
32
- if is_strict_match :
33
- return x [Ether ].dst == router_ether_addr and x [ICMPv6ND_NA ].tgt .startswith (expected_prefix )
34
- else :
35
- return x [ICMPv6ND_NA ].tgt .startswith (expected_prefix )
27
+ def is_expected_nd_ad (x , expected_prefix ):
28
+ return x [ICMPv6ND_NA ].tgt .startswith (expected_prefix )
36
29
37
- def main (outer_iface , outer_ether_addr , router_ether_addr , proxy_net_prefix ):
30
+ def main (outer_iface , proxy_net_prefix ):
31
+ outer_ether_addr = get_if_hwaddr (outer_iface )
38
32
sniff (filter = 'icmp6' ,
39
- lfilter = lambda x : is_expected_nd_so (x , proxy_net_prefix , router_ether_addr ) if ICMPv6ND_NS in x else is_expected_nd_ad (x , proxy_net_prefix , router_ether_addr ) if ICMPv6ND_NA in x else False ,
33
+ lfilter = lambda x : is_expected_nd_so (x , proxy_net_prefix ) if ICMPv6ND_NS in x else is_expected_nd_ad (x , proxy_net_prefix ) if ICMPv6ND_NA in x else False ,
40
34
prn = lambda x : (dump_nd_so (x ),send_nd_ad_for (x , outer_ether_addr ))[0 ] if ICMPv6ND_NS in x else dump_nd_ad (x ),
41
35
iface = outer_iface )
42
36
0 commit comments