|
|
@ -29,17 +29,24 @@ func udp(src, dst packet.IP, sport, dport uint16) []byte {
|
|
|
|
return packet.Generate(header, []byte("udp_payload"))
|
|
|
|
return packet.Generate(header, []byte("udp_payload"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func filterNet(ip, mask packet.IP) filter.Net {
|
|
|
|
|
|
|
|
return filter.Net{IP: ip, Mask: mask}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func nets(ips []packet.IP) []filter.Net {
|
|
|
|
func nets(ips []packet.IP) []filter.Net {
|
|
|
|
out := make([]filter.Net, 0, len(ips))
|
|
|
|
out := make([]filter.Net, 0, len(ips))
|
|
|
|
for _, ip := range ips {
|
|
|
|
for _, ip := range ips {
|
|
|
|
out = append(out, filter.Net{ip, filter.Netmask(32)})
|
|
|
|
out = append(out, filterNet(ip, filter.Netmask(32)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ippr(ip packet.IP, start, end uint16) []filter.NetPortRange {
|
|
|
|
func ippr(ip packet.IP, start, end uint16) []filter.NetPortRange {
|
|
|
|
return []filter.NetPortRange{
|
|
|
|
return []filter.NetPortRange{
|
|
|
|
filter.NetPortRange{filter.Net{ip, filter.Netmask(32)}, filter.PortRange{start, end}},
|
|
|
|
filter.NetPortRange{
|
|
|
|
|
|
|
|
Net: filterNet(ip, filter.Netmask(32)),
|
|
|
|
|
|
|
|
Ports: filter.PortRange{First: start, Last: end},
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +56,7 @@ func setfilter(logf logger.Logf, tun *TUN) {
|
|
|
|
{Srcs: nets([]packet.IP{0x01020304}), Dsts: ippr(0x05060708, 98, 98)},
|
|
|
|
{Srcs: nets([]packet.IP{0x01020304}), Dsts: ippr(0x05060708, 98, 98)},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
localNets := []filter.Net{
|
|
|
|
localNets := []filter.Net{
|
|
|
|
{packet.IP(0x01020304), filter.Netmask(16)},
|
|
|
|
filterNet(packet.IP(0x01020304), filter.Netmask(16)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tun.SetFilter(filter.New(matches, localNets, nil, logf))
|
|
|
|
tun.SetFilter(filter.New(matches, localNets, nil, logf))
|
|
|
|
}
|
|
|
|
}
|
|
|
|