in pkg/skoop/netstack/iptables.go [393:450]
func (t *AddrType) Match(ctx context.Context, packet *model.Packet, iif, oif string) (bool, error) {
var addr net.IP
switch t.Option {
case "src-type":
addr = packet.Src
case "dst-type":
addr = packet.Dst
case "limit-iface-in":
return iif == t.Value, nil
case "limit-iface-out":
return oif == t.Value, nil
}
switch t.Value {
case "UNSPEC":
return addr.IsUnspecified(), nil
case "MULTICAST":
return addr.IsMulticast(), nil
}
router, ok := ctx.Value(ContextRouterKey).(Router)
if !ok {
return false, fmt.Errorf("cannot get router from context, router: %#+v", router)
}
var addrType int
route, err := router.TableRoute(RtTableLocal, packet)
if err != nil {
if err == ErrNoRouteToHost {
addrType = RtnUnicast
} else {
return false, err
}
} else {
addrType = route.Type
}
switch t.Value {
case "UNICAST":
return addrType == RtnUnicast, nil
case "LOCAL":
return addrType == RtnLocal, nil
case "BROADCAST":
return addrType == RtnBroadcast, nil
case "ANYCAST":
return addrType == RtnAnycast, nil
case "MULTICAST":
return addrType == RtnMulticast, nil
case "BLACKHOLE":
return addrType == RtnBlackhole, nil
case "UNREACHABLE":
return addrType == RtnUnreachable, nil
case "PROHIBIT":
return addrType == RtnProhibit, nil
}
return false, nil
}