You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added fields to Nftable struct for better NFT_TABLE_NEW and GET functionality.
These fields include a UID referred to as a handle, an owner field, and a byte
slice to hold user-specified meta data. This allows us to validate more
scenarios when adding and retrieving a table.
PiperOrigin-RevId: 772235513
// If a table already exists, only update its dormant flags if NLM_F_EXCL and NLM_F_REPLACE
134
129
// are not set. From net/netfilter/nf_tables_api.c:nf_tables_newtable:nf_tables_updtable
135
130
iftab!=nil {
136
-
ifflags&linux.NLM_F_EXCL==linux.NLM_F_EXCL {
137
-
returnsyserr.NewAnnotatedError(syserr.ErrExists, fmt.Sprintf("Nftables: Table with name: %s already exists", tabNameBytes.String()))
131
+
ifflags&linux.NLM_F_EXCL!=0 {
132
+
returnsyserr.NewAnnotatedError(syserr.ErrExists, fmt.Sprintf("Nftables: Table with name: %s already exists", tab.GetName()))
133
+
}
134
+
135
+
ifflags&linux.NLM_F_REPLACE!=0 {
136
+
returnsyserr.NewAnnotatedError(syserr.ErrNotSupported, fmt.Sprintf("Nftables: Table with name: %s already exists and NLM_F_REPLACE is not supported", tab.GetName()))
137
+
}
138
+
139
+
returnp.updateTable(nft, tab, attrs, family, ms)
140
+
}
141
+
142
+
// TODO: b/421437663 - Support additional user-specified table flags.
143
+
varattrFlagsuint32=0
144
+
ifuflags, ok:=attrs[linux.NFTA_TABLE_FLAGS]; ok {
145
+
attrFlags, _=uflags.Uint32()
146
+
// Flags sent through the NFTA_TABLE_FLAGS attribute are of type uint32
147
+
// but should only have user flags set. This check needs to be done before table creation.
148
+
ifattrFlags&^uint32(linux.NFT_TABLE_F_MASK) !=0 {
149
+
returnsyserr.NewAnnotatedError(syserr.ErrNotSupported, fmt.Sprintf("Nftables: Table flags set are not supported"))
returnsyserr.NewAnnotatedError(syserr.ErrNotSupported, fmt.Sprintf("Nftables: Table with name: %s already exists and NLM_F_REPLACE is not supported", tabNameBytes.String()))
173
+
returnnil
174
+
}
175
+
176
+
// updateTable updates an existing table.
177
+
func (p*Protocol) updateTable(nft*nftables.NFTables, tab*nftables.Table, attrsmap[uint16]nlmsg.BytesView, family stack.AddressFamily, ms*nlmsg.MessageSet) *syserr.AnnotatedError {
178
+
varattrFlagsuint32
179
+
ifuflags, ok:=attrs[linux.NFTA_TABLE_FLAGS]; ok {
180
+
attrFlags, _=uflags.Uint32()
181
+
// This check needs to be done before table update.
182
+
ifattrFlags&^uint32(linux.NFT_TABLE_F_MASK) >0 {
183
+
returnsyserr.NewAnnotatedError(syserr.ErrNotSupported, fmt.Sprintf("Nftables: Table flags set are not supported"))
returnsyserr.NewAnnotatedError(syserr.ErrNotSupported, fmt.Sprintf("Nftables: Table with name: %s already has an owner but NFT_TABLE_F_OWNER was not set when updating the table", tab.GetName()))
192
+
}
193
+
194
+
// The owner is only updated if the table has no previous owner.
returnnil, syserr.NewAnnotatedError(syserr.ErrNotPermitted, fmt.Sprintf("table %s has owner %d, which does not match the Netlink portID of the calling process %d", tableName, t.GetOwner(), portID))
0 commit comments