@@ -1102,6 +1102,25 @@ func fillRuleInfo(rule *nftables.Rule, ms *nlmsg.MessageSet) *syserr.AnnotatedEr
11021102 return nil
11031103}
11041104
1105+ // getGen returns the generation info for the current nftables instance.
1106+ func (p * Protocol ) getGen (nft * nftables.NFTables , task * kernel.Task , attrs map [uint16 ]nlmsg.BytesView , family stack.AddressFamily , msgFlags uint16 , ms * nlmsg.MessageSet ) * syserr.AnnotatedError {
1107+ m := ms .AddMessage (linux.NetlinkMessageHeader {
1108+ Type : uint16 (linux .NFNL_SUBSYS_NFTABLES )<< 8 | uint16 (linux .NFT_MSG_NEWGEN ),
1109+ })
1110+ m .Put (& linux.NetFilterGenMsg {
1111+ Family : uint8 (nftables .AfProtocol (stack .Unspec )),
1112+ Version : uint8 (linux .NFNETLINK_V0 ),
1113+ // Unused, set to 0.
1114+ ResourceID : uint16 (0 ),
1115+ })
1116+
1117+ m .PutAttr (linux .NFTA_GEN_ID , nlmsg .PutU32 (nft .GetGenID ()))
1118+ m .PutAttr (linux .NFTA_GEN_PROC_PID , nlmsg .PutU32 (uint32 (task .ThreadGroup ().ID ())))
1119+ // TODO - b/434244017: Add support for dumping the process name.
1120+ m .PutAttrString (linux .NFTA_GEN_PROC_NAME , "placeholder" )
1121+ return nil
1122+ }
1123+
11051124// isNetDevHook returns whether the given family and hook number represent a
11061125// netdev hook, or if the family is inet and is attempting to attach to
11071126// Ingress or Egress hooks.
@@ -1170,9 +1189,20 @@ func (p *Protocol) ProcessMessage(ctx context.Context, s *netlink.Socket, msg *n
11701189 }
11711190
11721191 return nil
1173- case linux .NFT_MSG_GETRULE_RESET ,
1174- linux .NFT_MSG_GETSET , linux .NFT_MSG_GETSETELEM ,
1175- linux .NFT_MSG_GETSETELEM_RESET , linux .NFT_MSG_GETGEN ,
1192+ case linux .NFT_MSG_GETGEN :
1193+ if err := p .getGen (nft , kernel .TaskFromContext (ctx ), attrs , family , hdr .Flags , ms ); err != nil {
1194+ log .Debugf ("Nftables get gen error: %s" , err )
1195+ return err .GetError ()
1196+ }
1197+ return nil
1198+ case linux .NFT_MSG_GETSET :
1199+ // TODO - b/421437663: Implement sets for nftables. This skeleton is
1200+ // left here to satisfy auxiliary calls from the nft CLI not needed
1201+ // for packet filtering functionality.
1202+ ms .Multi = true
1203+ return nil
1204+ case linux .NFT_MSG_GETRULE_RESET , linux .NFT_MSG_GETSETELEM ,
1205+ linux .NFT_MSG_GETSETELEM_RESET ,
11761206 linux .NFT_MSG_GETOBJ , linux .NFT_MSG_GETOBJ_RESET ,
11771207 linux .NFT_MSG_GETFLOWTABLE :
11781208
0 commit comments