From 0c96bf2ad2f63ddca1d2f2277df2230be3109640 Mon Sep 17 00:00:00 2001 From: Daniel Grau Date: Thu, 10 Oct 2024 23:25:47 +0000 Subject: [PATCH] Send genetlink packet to netdev too --- dataplane/saiserver/hostif.go | 33 +++++++++++++++++++++++++++++++-- dataplane/saiserver/switch.go | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/dataplane/saiserver/hostif.go b/dataplane/saiserver/hostif.go index a86d7a09..f6e5789c 100644 --- a/dataplane/saiserver/hostif.go +++ b/dataplane/saiserver/hostif.go @@ -324,15 +324,44 @@ const ( ) func (hostif *hostif) CreateHostifTableEntry(ctx context.Context, req *saipb.CreateHostifTableEntryRequest) (*saipb.CreateHostifTableEntryResponse, error) { + cpuPortReq := &saipb.GetSwitchAttributeRequest{Oid: switchID, AttrType: []saipb.SwitchAttr{saipb.SwitchAttr_SWITCH_ATTR_CPU_PORT}} + resp := &saipb.GetSwitchAttributeResponse{} + if err := hostif.mgr.PopulateAttributes(cpuPortReq, resp); err != nil { + return nil, err + } + switch entryType := req.GetType(); entryType { case saipb.HostifTableEntryType_HOSTIF_TABLE_ENTRY_TYPE_TRAP_ID: hostif.trapIDToHostifID[req.GetTrapId()] = req.GetHostIf() - _, err := hostif.dataplane.TableEntryAdd(ctx, fwdconfig.TableEntryAddRequest(hostif.dataplane.ID(), trapIDToHostifTable). + tReq := fwdconfig.TableEntryAddRequest(hostif.dataplane.ID(), trapIDToHostifTable). AppendEntry( fwdconfig.EntryDesc(fwdconfig.ExactEntry( fwdconfig.PacketFieldBytes(fwdpb.PacketFieldNum_PACKET_FIELD_NUM_TRAP_ID).WithUint64(req.GetTrapId()))), fwdconfig.Action(fwdconfig.UpdateAction(fwdpb.UpdateType_UPDATE_TYPE_SET, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_HOST_PORT_ID).WithUint64Value(req.GetHostIf()))). - Build()) + Build() + + hostifReq := &saipb.GetHostifAttributeRequest{Oid: req.GetHostIf(), AttrType: []saipb.HostifAttr{saipb.HostifAttr_HOSTIF_ATTR_TYPE}} + hostifResp := &saipb.GetHostifAttributeResponse{} + if err := hostif.mgr.PopulateAttributes(hostifReq, hostifResp); err != nil { + return nil, err + } + // For GENETLINK trap rules, also send the packet to the correct netdev. + if hostifResp.GetAttr().GetType() == saipb.HostifType_HOSTIF_TYPE_GENETLINK { + tReq.Entries[0].Actions = append(tReq.Entries[0].Actions, &fwdpb.ActionDesc{ + ActionType: fwdpb.ActionType_ACTION_TYPE_MIRROR, + Action: &fwdpb.ActionDesc_Mirror{ + Mirror: &fwdpb.MirrorActionDesc{ + FieldIds: []*fwdpb.PacketFieldId{}, + PortAction: fwdpb.PortAction_PORT_ACTION_OUTPUT, + PortId: &fwdpb.PortId{ + ObjectId: &fwdpb.ObjectId{Id: fmt.Sprint(resp.GetAttr().GetCpuPort())}, + }, + }, + }, + }) + } + + _, err := hostif.dataplane.TableEntryAdd(ctx, tReq) if err != nil { return nil, err } diff --git a/dataplane/saiserver/switch.go b/dataplane/saiserver/switch.go index 8295e325..8e26b5cd 100644 --- a/dataplane/saiserver/switch.go +++ b/dataplane/saiserver/switch.go @@ -855,7 +855,7 @@ func (sw *saiSwitch) CreateSwitch(ctx context.Context, _ *saipb.CreateSwitchRequ func (sw *saiSwitch) createInvalidPacketFilter(ctx context.Context) error { ips := map[string]map[fwdpb.PacketFieldNum][]string{ invalidIngressV4Table: { - fwdpb.PacketFieldNum_PACKET_FIELD_NUM_IP_ADDR_SRC: {"224.0.0.0/4", "127.0.0.0/8"}, + fwdpb.PacketFieldNum_PACKET_FIELD_NUM_IP_ADDR_SRC: {"127.0.0.0/8"}, fwdpb.PacketFieldNum_PACKET_FIELD_NUM_IP_ADDR_DST: {"224.0.0.0/4", "127.0.0.0/8", "255.255.255.255/24"}, }, invalidIngressV6Table: {