1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _NET_NF_TABLES_H 3 #define _NET_NF_TABLES_H 4 5 #include <asm/unaligned.h> 6 #include <linux/list.h> 7 #include <linux/netfilter.h> 8 #include <linux/netfilter/nfnetlink.h> 9 #include <linux/netfilter/x_tables.h> 10 #include <linux/netfilter/nf_tables.h> 11 #include <linux/u64_stats_sync.h> 12 #include <linux/rhashtable.h> 13 #include <net/netfilter/nf_flow_table.h> 14 #include <net/netlink.h> 15 #include <net/flow_offload.h> 16 17 struct module; 18 19 #define NFT_JUMP_STACK_SIZE 16 20 21 struct nft_pktinfo { 22 struct sk_buff *skb; 23 bool tprot_set; 24 u8 tprot; 25 /* for x_tables compatibility */ 26 struct xt_action_param xt; 27 }; 28 29 static inline struct net *nft_net(const struct nft_pktinfo *pkt) 30 { 31 return pkt->xt.state->net; 32 } 33 34 static inline unsigned int nft_hook(const struct nft_pktinfo *pkt) 35 { 36 return pkt->xt.state->hook; 37 } 38 39 static inline u8 nft_pf(const struct nft_pktinfo *pkt) 40 { 41 return pkt->xt.state->pf; 42 } 43 44 static inline const struct net_device *nft_in(const struct nft_pktinfo *pkt) 45 { 46 return pkt->xt.state->in; 47 } 48 49 static inline const struct net_device *nft_out(const struct nft_pktinfo *pkt) 50 { 51 return pkt->xt.state->out; 52 } 53 54 static inline void nft_set_pktinfo(struct nft_pktinfo *pkt, 55 struct sk_buff *skb, 56 const struct nf_hook_state *state) 57 { 58 pkt->skb = skb; 59 pkt->xt.state = state; 60 } 61 62 static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt, 63 struct sk_buff *skb) 64 { 65 pkt->tprot_set = false; 66 pkt->tprot = 0; 67 pkt->xt.thoff = 0; 68 pkt->xt.fragoff = 0; 69 } 70 71 /** 72 * struct nft_verdict - nf_tables verdict 73 * 74 * @code: nf_tables/netfilter verdict code 75 * @chain: destination chain for NFT_JUMP/NFT_GOTO 76 */ 77 struct nft_verdict { 78 u32 code; 79 struct nft_chain *chain; 80 }; 81 82 struct nft_data { 83 union { 84 u32 data[4]; 85 struct nft_verdict verdict; 86 }; 87 } __attribute__((aligned(__alignof__(u64)))); 88 89 /** 90 * struct nft_regs - nf_tables register set 91 * 92 * @data: data registers 93 * @verdict: verdict register 94 * 95 * The first four data registers alias to the verdict register. 96 */ 97 struct nft_regs { 98 union { 99 u32 data[20]; 100 struct nft_verdict verdict; 101 }; 102 }; 103 104 /* Store/load an u8, u16 or u64 integer to/from the u32 data register. 105 * 106 * Note, when using concatenations, register allocation happens at 32-bit 107 * level. So for store instruction, pad the rest part with zero to avoid 108 * garbage values. 109 */ 110 111 static inline void nft_reg_store8(u32 *dreg, u8 val) 112 { 113 *dreg = 0; 114 *(u8 *)dreg = val; 115 } 116 117 static inline u8 nft_reg_load8(const u32 *sreg) 118 { 119 return *(u8 *)sreg; 120 } 121 122 static inline void nft_reg_store16(u32 *dreg, u16 val) 123 { 124 *dreg = 0; 125 *(u16 *)dreg = val; 126 } 127 128 static inline u16 nft_reg_load16(const u32 *sreg) 129 { 130 return *(u16 *)sreg; 131 } 132 133 static inline void nft_reg_store64(u32 *dreg, u64 val) 134 { 135 put_unaligned(val, (u64 *)dreg); 136 } 137 138 static inline u64 nft_reg_load64(const u32 *sreg) 139 { 140 return get_unaligned((u64 *)sreg); 141 } 142 143 static inline void nft_data_copy(u32 *dst, const struct nft_data *src, 144 unsigned int len) 145 { 146 memcpy(dst, src, len); 147 } 148 149 static inline void nft_data_debug(const struct nft_data *data) 150 { 151 pr_debug("data[0]=%x data[1]=%x data[2]=%x data[3]=%x\n", 152 data->data[0], data->data[1], 153 data->data[2], data->data[3]); 154 } 155 156 /** 157 * struct nft_ctx - nf_tables rule/set context 158 * 159 * @net: net namespace 160 * @table: the table the chain is contained in 161 * @chain: the chain the rule is contained in 162 * @nla: netlink attributes 163 * @portid: netlink portID of the original message 164 * @seq: netlink sequence number 165 * @family: protocol family 166 * @level: depth of the chains 167 * @report: notify via unicast netlink message 168 */ 169 struct nft_ctx { 170 struct net *net; 171 struct nft_table *table; 172 struct nft_chain *chain; 173 const struct nlattr * const *nla; 174 u32 portid; 175 u32 seq; 176 u16 flags; 177 u8 family; 178 u8 level; 179 bool report; 180 }; 181 182 struct nft_data_desc { 183 enum nft_data_types type; 184 unsigned int len; 185 }; 186 187 int nft_data_init(const struct nft_ctx *ctx, 188 struct nft_data *data, unsigned int size, 189 struct nft_data_desc *desc, const struct nlattr *nla); 190 void nft_data_hold(const struct nft_data *data, enum nft_data_types type); 191 void nft_data_release(const struct nft_data *data, enum nft_data_types type); 192 int nft_data_dump(struct sk_buff *skb, int attr, const struct nft_data *data, 193 enum nft_data_types type, unsigned int len); 194 195 static inline enum nft_data_types nft_dreg_to_type(enum nft_registers reg) 196 { 197 return reg == NFT_REG_VERDICT ? NFT_DATA_VERDICT : NFT_DATA_VALUE; 198 } 199 200 static inline enum nft_registers nft_type_to_reg(enum nft_data_types type) 201 { 202 return type == NFT_DATA_VERDICT ? NFT_REG_VERDICT : NFT_REG_1 * NFT_REG_SIZE / NFT_REG32_SIZE; 203 } 204 205 int nft_parse_u32_check(const struct nlattr *attr, int max, u32 *dest); 206 unsigned int nft_parse_register(const struct nlattr *attr); 207 int nft_dump_register(struct sk_buff *skb, unsigned int attr, unsigned int reg); 208 209 int nft_validate_register_load(enum nft_registers reg, unsigned int len); 210 int nft_validate_register_store(const struct nft_ctx *ctx, 211 enum nft_registers reg, 212 const struct nft_data *data, 213 enum nft_data_types type, unsigned int len); 214 215 /** 216 * struct nft_userdata - user defined data associated with an object 217 * 218 * @len: length of the data 219 * @data: content 220 * 221 * The presence of user data is indicated in an object specific fashion, 222 * so a length of zero can't occur and the value "len" indicates data 223 * of length len + 1. 224 */ 225 struct nft_userdata { 226 u8 len; 227 unsigned char data[]; 228 }; 229 230 /** 231 * struct nft_set_elem - generic representation of set elements 232 * 233 * @key: element key 234 * @key_end: closing element key 235 * @priv: element private data and extensions 236 */ 237 struct nft_set_elem { 238 union { 239 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)]; 240 struct nft_data val; 241 } key; 242 union { 243 u32 buf[NFT_DATA_VALUE_MAXLEN / sizeof(u32)]; 244 struct nft_data val; 245 } key_end; 246 void *priv; 247 }; 248 249 struct nft_set; 250 struct nft_set_iter { 251 u8 genmask; 252 unsigned int count; 253 unsigned int skip; 254 int err; 255 int (*fn)(const struct nft_ctx *ctx, 256 struct nft_set *set, 257 const struct nft_set_iter *iter, 258 struct nft_set_elem *elem); 259 }; 260 261 /** 262 * struct nft_set_desc - description of set elements 263 * 264 * @klen: key length 265 * @dlen: data length 266 * @size: number of set elements 267 * @field_len: length of each field in concatenation, bytes 268 * @field_count: number of concatenated fields in element 269 */ 270 struct nft_set_desc { 271 unsigned int klen; 272 unsigned int dlen; 273 unsigned int size; 274 u8 field_len[NFT_REG32_COUNT]; 275 u8 field_count; 276 }; 277 278 /** 279 * enum nft_set_class - performance class 280 * 281 * @NFT_LOOKUP_O_1: constant, O(1) 282 * @NFT_LOOKUP_O_LOG_N: logarithmic, O(log N) 283 * @NFT_LOOKUP_O_N: linear, O(N) 284 */ 285 enum nft_set_class { 286 NFT_SET_CLASS_O_1, 287 NFT_SET_CLASS_O_LOG_N, 288 NFT_SET_CLASS_O_N, 289 }; 290 291 /** 292 * struct nft_set_estimate - estimation of memory and performance 293 * characteristics 294 * 295 * @size: required memory 296 * @lookup: lookup performance class 297 * @space: memory class 298 */ 299 struct nft_set_estimate { 300 u64 size; 301 enum nft_set_class lookup; 302 enum nft_set_class space; 303 }; 304 305 struct nft_set_ext; 306 struct nft_expr; 307 308 /** 309 * struct nft_set_ops - nf_tables set operations 310 * 311 * @lookup: look up an element within the set 312 * @update: update an element if exists, add it if doesn't exist 313 * @delete: delete an element 314 * @insert: insert new element into set 315 * @activate: activate new element in the next generation 316 * @deactivate: lookup for element and deactivate it in the next generation 317 * @flush: deactivate element in the next generation 318 * @remove: remove element from set 319 * @walk: iterate over all set elements 320 * @get: get set elements 321 * @privsize: function to return size of set private data 322 * @init: initialize private data of new set instance 323 * @destroy: destroy private data of set instance 324 * @elemsize: element private size 325 * 326 * Operations lookup, update and delete have simpler interfaces, are faster 327 * and currently only used in the packet path. All the rest are slower, 328 * control plane functions. 329 */ 330 struct nft_set_ops { 331 bool (*lookup)(const struct net *net, 332 const struct nft_set *set, 333 const u32 *key, 334 const struct nft_set_ext **ext); 335 bool (*update)(struct nft_set *set, 336 const u32 *key, 337 void *(*new)(struct nft_set *, 338 const struct nft_expr *, 339 struct nft_regs *), 340 const struct nft_expr *expr, 341 struct nft_regs *regs, 342 const struct nft_set_ext **ext); 343 bool (*delete)(const struct nft_set *set, 344 const u32 *key); 345 346 int (*insert)(const struct net *net, 347 const struct nft_set *set, 348 const struct nft_set_elem *elem, 349 struct nft_set_ext **ext); 350 void (*activate)(const struct net *net, 351 const struct nft_set *set, 352 const struct nft_set_elem *elem); 353 void * (*deactivate)(const struct net *net, 354 const struct nft_set *set, 355 const struct nft_set_elem *elem); 356 bool (*flush)(const struct net *net, 357 const struct nft_set *set, 358 void *priv); 359 void (*remove)(const struct net *net, 360 const struct nft_set *set, 361 const struct nft_set_elem *elem); 362 void (*walk)(const struct nft_ctx *ctx, 363 struct nft_set *set, 364 struct nft_set_iter *iter); 365 void * (*get)(const struct net *net, 366 const struct nft_set *set, 367 const struct nft_set_elem *elem, 368 unsigned int flags); 369 370 u64 (*privsize)(const struct nlattr * const nla[], 371 const struct nft_set_desc *desc); 372 bool (*estimate)(const struct nft_set_desc *desc, 373 u32 features, 374 struct nft_set_estimate *est); 375 int (*init)(const struct nft_set *set, 376 const struct nft_set_desc *desc, 377 const struct nlattr * const nla[]); 378 void (*destroy)(const struct nft_set *set); 379 void (*gc_init)(const struct nft_set *set); 380 381 unsigned int elemsize; 382 }; 383 384 /** 385 * struct nft_set_type - nf_tables set type 386 * 387 * @ops: set ops for this type 388 * @features: features supported by the implementation 389 */ 390 struct nft_set_type { 391 const struct nft_set_ops ops; 392 u32 features; 393 }; 394 #define to_set_type(o) container_of(o, struct nft_set_type, ops) 395 396 /** 397 * struct nft_set - nf_tables set instance 398 * 399 * @list: table set list node 400 * @bindings: list of set bindings 401 * @table: table this set belongs to 402 * @net: netnamespace this set belongs to 403 * @name: name of the set 404 * @handle: unique handle of the set 405 * @ktype: key type (numeric type defined by userspace, not used in the kernel) 406 * @dtype: data type (verdict or numeric type defined by userspace) 407 * @objtype: object type (see NFT_OBJECT_* definitions) 408 * @size: maximum set size 409 * @field_len: length of each field in concatenation, bytes 410 * @field_count: number of concatenated fields in element 411 * @use: number of rules references to this set 412 * @nelems: number of elements 413 * @ndeact: number of deactivated elements queued for removal 414 * @timeout: default timeout value in jiffies 415 * @gc_int: garbage collection interval in msecs 416 * @policy: set parameterization (see enum nft_set_policies) 417 * @udlen: user data length 418 * @udata: user data 419 * @ops: set ops 420 * @flags: set flags 421 * @genmask: generation mask 422 * @klen: key length 423 * @dlen: data length 424 * @data: private set data 425 */ 426 struct nft_set { 427 struct list_head list; 428 struct list_head bindings; 429 struct nft_table *table; 430 possible_net_t net; 431 char *name; 432 u64 handle; 433 u32 ktype; 434 u32 dtype; 435 u32 objtype; 436 u32 size; 437 u8 field_len[NFT_REG32_COUNT]; 438 u8 field_count; 439 u32 use; 440 atomic_t nelems; 441 u32 ndeact; 442 u64 timeout; 443 u32 gc_int; 444 u16 policy; 445 u16 udlen; 446 unsigned char *udata; 447 /* runtime data below here */ 448 const struct nft_set_ops *ops ____cacheline_aligned; 449 u16 flags:14, 450 genmask:2; 451 u8 klen; 452 u8 dlen; 453 unsigned char data[] 454 __attribute__((aligned(__alignof__(u64)))); 455 }; 456 457 static inline bool nft_set_is_anonymous(const struct nft_set *set) 458 { 459 return set->flags & NFT_SET_ANONYMOUS; 460 } 461 462 static inline void *nft_set_priv(const struct nft_set *set) 463 { 464 return (void *)set->data; 465 } 466 467 static inline struct nft_set *nft_set_container_of(const void *priv) 468 { 469 return (void *)priv - offsetof(struct nft_set, data); 470 } 471 472 struct nft_set *nft_set_lookup_global(const struct net *net, 473 const struct nft_table *table, 474 const struct nlattr *nla_set_name, 475 const struct nlattr *nla_set_id, 476 u8 genmask); 477 478 static inline unsigned long nft_set_gc_interval(const struct nft_set *set) 479 { 480 return set->gc_int ? msecs_to_jiffies(set->gc_int) : HZ; 481 } 482 483 /** 484 * struct nft_set_binding - nf_tables set binding 485 * 486 * @list: set bindings list node 487 * @chain: chain containing the rule bound to the set 488 * @flags: set action flags 489 * 490 * A set binding contains all information necessary for validation 491 * of new elements added to a bound set. 492 */ 493 struct nft_set_binding { 494 struct list_head list; 495 const struct nft_chain *chain; 496 u32 flags; 497 }; 498 499 enum nft_trans_phase; 500 void nf_tables_deactivate_set(const struct nft_ctx *ctx, struct nft_set *set, 501 struct nft_set_binding *binding, 502 enum nft_trans_phase phase); 503 int nf_tables_bind_set(const struct nft_ctx *ctx, struct nft_set *set, 504 struct nft_set_binding *binding); 505 void nf_tables_destroy_set(const struct nft_ctx *ctx, struct nft_set *set); 506 507 /** 508 * enum nft_set_extensions - set extension type IDs 509 * 510 * @NFT_SET_EXT_KEY: element key 511 * @NFT_SET_EXT_KEY_END: upper bound element key, for ranges 512 * @NFT_SET_EXT_DATA: mapping data 513 * @NFT_SET_EXT_FLAGS: element flags 514 * @NFT_SET_EXT_TIMEOUT: element timeout 515 * @NFT_SET_EXT_EXPIRATION: element expiration time 516 * @NFT_SET_EXT_USERDATA: user data associated with the element 517 * @NFT_SET_EXT_EXPR: expression assiociated with the element 518 * @NFT_SET_EXT_OBJREF: stateful object reference associated with element 519 * @NFT_SET_EXT_NUM: number of extension types 520 */ 521 enum nft_set_extensions { 522 NFT_SET_EXT_KEY, 523 NFT_SET_EXT_KEY_END, 524 NFT_SET_EXT_DATA, 525 NFT_SET_EXT_FLAGS, 526 NFT_SET_EXT_TIMEOUT, 527 NFT_SET_EXT_EXPIRATION, 528 NFT_SET_EXT_USERDATA, 529 NFT_SET_EXT_EXPR, 530 NFT_SET_EXT_OBJREF, 531 NFT_SET_EXT_NUM 532 }; 533 534 /** 535 * struct nft_set_ext_type - set extension type 536 * 537 * @len: fixed part length of the extension 538 * @align: alignment requirements of the extension 539 */ 540 struct nft_set_ext_type { 541 u8 len; 542 u8 align; 543 }; 544 545 extern const struct nft_set_ext_type nft_set_ext_types[]; 546 547 /** 548 * struct nft_set_ext_tmpl - set extension template 549 * 550 * @len: length of extension area 551 * @offset: offsets of individual extension types 552 */ 553 struct nft_set_ext_tmpl { 554 u16 len; 555 u8 offset[NFT_SET_EXT_NUM]; 556 }; 557 558 /** 559 * struct nft_set_ext - set extensions 560 * 561 * @genmask: generation mask 562 * @offset: offsets of individual extension types 563 * @data: beginning of extension data 564 */ 565 struct nft_set_ext { 566 u8 genmask; 567 u8 offset[NFT_SET_EXT_NUM]; 568 char data[]; 569 }; 570 571 static inline void nft_set_ext_prepare(struct nft_set_ext_tmpl *tmpl) 572 { 573 memset(tmpl, 0, sizeof(*tmpl)); 574 tmpl->len = sizeof(struct nft_set_ext); 575 } 576 577 static inline void nft_set_ext_add_length(struct nft_set_ext_tmpl *tmpl, u8 id, 578 unsigned int len) 579 { 580 tmpl->len = ALIGN(tmpl->len, nft_set_ext_types[id].align); 581 BUG_ON(tmpl->len > U8_MAX); 582 tmpl->offset[id] = tmpl->len; 583 tmpl->len += nft_set_ext_types[id].len + len; 584 } 585 586 static inline void nft_set_ext_add(struct nft_set_ext_tmpl *tmpl, u8 id) 587 { 588 nft_set_ext_add_length(tmpl, id, 0); 589 } 590 591 static inline void nft_set_ext_init(struct nft_set_ext *ext, 592 const struct nft_set_ext_tmpl *tmpl) 593 { 594 memcpy(ext->offset, tmpl->offset, sizeof(ext->offset)); 595 } 596 597 static inline bool __nft_set_ext_exists(const struct nft_set_ext *ext, u8 id) 598 { 599 return !!ext->offset[id]; 600 } 601 602 static inline bool nft_set_ext_exists(const struct nft_set_ext *ext, u8 id) 603 { 604 return ext && __nft_set_ext_exists(ext, id); 605 } 606 607 static inline void *nft_set_ext(const struct nft_set_ext *ext, u8 id) 608 { 609 return (void *)ext + ext->offset[id]; 610 } 611 612 static inline struct nft_data *nft_set_ext_key(const struct nft_set_ext *ext) 613 { 614 return nft_set_ext(ext, NFT_SET_EXT_KEY); 615 } 616 617 static inline struct nft_data *nft_set_ext_key_end(const struct nft_set_ext *ext) 618 { 619 return nft_set_ext(ext, NFT_SET_EXT_KEY_END); 620 } 621 622 static inline struct nft_data *nft_set_ext_data(const struct nft_set_ext *ext) 623 { 624 return nft_set_ext(ext, NFT_SET_EXT_DATA); 625 } 626 627 static inline u8 *nft_set_ext_flags(const struct nft_set_ext *ext) 628 { 629 return nft_set_ext(ext, NFT_SET_EXT_FLAGS); 630 } 631 632 static inline u64 *nft_set_ext_timeout(const struct nft_set_ext *ext) 633 { 634 return nft_set_ext(ext, NFT_SET_EXT_TIMEOUT); 635 } 636 637 static inline u64 *nft_set_ext_expiration(const struct nft_set_ext *ext) 638 { 639 return nft_set_ext(ext, NFT_SET_EXT_EXPIRATION); 640 } 641 642 static inline struct nft_userdata *nft_set_ext_userdata(const struct nft_set_ext *ext) 643 { 644 return nft_set_ext(ext, NFT_SET_EXT_USERDATA); 645 } 646 647 static inline struct nft_expr *nft_set_ext_expr(const struct nft_set_ext *ext) 648 { 649 return nft_set_ext(ext, NFT_SET_EXT_EXPR); 650 } 651 652 static inline bool nft_set_elem_expired(const struct nft_set_ext *ext) 653 { 654 return nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION) && 655 time_is_before_eq_jiffies64(*nft_set_ext_expiration(ext)); 656 } 657 658 static inline struct nft_set_ext *nft_set_elem_ext(const struct nft_set *set, 659 void *elem) 660 { 661 return elem + set->ops->elemsize; 662 } 663 664 static inline struct nft_object **nft_set_ext_obj(const struct nft_set_ext *ext) 665 { 666 return nft_set_ext(ext, NFT_SET_EXT_OBJREF); 667 } 668 669 struct nft_expr *nft_set_elem_expr_alloc(const struct nft_ctx *ctx, 670 const struct nft_set *set, 671 const struct nlattr *attr); 672 673 void *nft_set_elem_init(const struct nft_set *set, 674 const struct nft_set_ext_tmpl *tmpl, 675 const u32 *key, const u32 *key_end, const u32 *data, 676 u64 timeout, u64 expiration, gfp_t gfp); 677 void nft_set_elem_destroy(const struct nft_set *set, void *elem, 678 bool destroy_expr); 679 680 /** 681 * struct nft_set_gc_batch_head - nf_tables set garbage collection batch 682 * 683 * @rcu: rcu head 684 * @set: set the elements belong to 685 * @cnt: count of elements 686 */ 687 struct nft_set_gc_batch_head { 688 struct rcu_head rcu; 689 const struct nft_set *set; 690 unsigned int cnt; 691 }; 692 693 #define NFT_SET_GC_BATCH_SIZE ((PAGE_SIZE - \ 694 sizeof(struct nft_set_gc_batch_head)) / \ 695 sizeof(void *)) 696 697 /** 698 * struct nft_set_gc_batch - nf_tables set garbage collection batch 699 * 700 * @head: GC batch head 701 * @elems: garbage collection elements 702 */ 703 struct nft_set_gc_batch { 704 struct nft_set_gc_batch_head head; 705 void *elems[NFT_SET_GC_BATCH_SIZE]; 706 }; 707 708 struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set, 709 gfp_t gfp); 710 void nft_set_gc_batch_release(struct rcu_head *rcu); 711 712 static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb) 713 { 714 if (gcb != NULL) 715 call_rcu(&gcb->head.rcu, nft_set_gc_batch_release); 716 } 717 718 static inline struct nft_set_gc_batch * 719 nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb, 720 gfp_t gfp) 721 { 722 if (gcb != NULL) { 723 if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems)) 724 return gcb; 725 nft_set_gc_batch_complete(gcb); 726 } 727 return nft_set_gc_batch_alloc(set, gfp); 728 } 729 730 static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb, 731 void *elem) 732 { 733 gcb->elems[gcb->head.cnt++] = elem; 734 } 735 736 struct nft_expr_ops; 737 /** 738 * struct nft_expr_type - nf_tables expression type 739 * 740 * @select_ops: function to select nft_expr_ops 741 * @release_ops: release nft_expr_ops 742 * @ops: default ops, used when no select_ops functions is present 743 * @list: used internally 744 * @name: Identifier 745 * @owner: module reference 746 * @policy: netlink attribute policy 747 * @maxattr: highest netlink attribute number 748 * @family: address family for AF-specific types 749 * @flags: expression type flags 750 */ 751 struct nft_expr_type { 752 const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *, 753 const struct nlattr * const tb[]); 754 void (*release_ops)(const struct nft_expr_ops *ops); 755 const struct nft_expr_ops *ops; 756 struct list_head list; 757 const char *name; 758 struct module *owner; 759 const struct nla_policy *policy; 760 unsigned int maxattr; 761 u8 family; 762 u8 flags; 763 }; 764 765 #define NFT_EXPR_STATEFUL 0x1 766 #define NFT_EXPR_GC 0x2 767 768 enum nft_trans_phase { 769 NFT_TRANS_PREPARE, 770 NFT_TRANS_ABORT, 771 NFT_TRANS_COMMIT, 772 NFT_TRANS_RELEASE 773 }; 774 775 struct nft_flow_rule; 776 struct nft_offload_ctx; 777 778 /** 779 * struct nft_expr_ops - nf_tables expression operations 780 * 781 * @eval: Expression evaluation function 782 * @size: full expression size, including private data size 783 * @init: initialization function 784 * @activate: activate expression in the next generation 785 * @deactivate: deactivate expression in next generation 786 * @destroy: destruction function, called after synchronize_rcu 787 * @dump: function to dump parameters 788 * @type: expression type 789 * @validate: validate expression, called during loop detection 790 * @data: extra data to attach to this expression operation 791 */ 792 struct nft_expr; 793 struct nft_expr_ops { 794 void (*eval)(const struct nft_expr *expr, 795 struct nft_regs *regs, 796 const struct nft_pktinfo *pkt); 797 int (*clone)(struct nft_expr *dst, 798 const struct nft_expr *src); 799 unsigned int size; 800 801 int (*init)(const struct nft_ctx *ctx, 802 const struct nft_expr *expr, 803 const struct nlattr * const tb[]); 804 void (*activate)(const struct nft_ctx *ctx, 805 const struct nft_expr *expr); 806 void (*deactivate)(const struct nft_ctx *ctx, 807 const struct nft_expr *expr, 808 enum nft_trans_phase phase); 809 void (*destroy)(const struct nft_ctx *ctx, 810 const struct nft_expr *expr); 811 void (*destroy_clone)(const struct nft_ctx *ctx, 812 const struct nft_expr *expr); 813 int (*dump)(struct sk_buff *skb, 814 const struct nft_expr *expr); 815 int (*validate)(const struct nft_ctx *ctx, 816 const struct nft_expr *expr, 817 const struct nft_data **data); 818 bool (*gc)(struct net *net, 819 const struct nft_expr *expr); 820 int (*offload)(struct nft_offload_ctx *ctx, 821 struct nft_flow_rule *flow, 822 const struct nft_expr *expr); 823 u32 offload_flags; 824 const struct nft_expr_type *type; 825 void *data; 826 }; 827 828 #define NFT_EXPR_MAXATTR 16 829 #define NFT_EXPR_SIZE(size) (sizeof(struct nft_expr) + \ 830 ALIGN(size, __alignof__(struct nft_expr))) 831 832 /** 833 * struct nft_expr - nf_tables expression 834 * 835 * @ops: expression ops 836 * @data: expression private data 837 */ 838 struct nft_expr { 839 const struct nft_expr_ops *ops; 840 unsigned char data[] 841 __attribute__((aligned(__alignof__(u64)))); 842 }; 843 844 static inline void *nft_expr_priv(const struct nft_expr *expr) 845 { 846 return (void *)expr->data; 847 } 848 849 void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr); 850 int nft_expr_dump(struct sk_buff *skb, unsigned int attr, 851 const struct nft_expr *expr); 852 853 /** 854 * struct nft_rule - nf_tables rule 855 * 856 * @list: used internally 857 * @handle: rule handle 858 * @genmask: generation mask 859 * @dlen: length of expression data 860 * @udata: user data is appended to the rule 861 * @data: expression data 862 */ 863 struct nft_rule { 864 struct list_head list; 865 u64 handle:42, 866 genmask:2, 867 dlen:12, 868 udata:1; 869 unsigned char data[] 870 __attribute__((aligned(__alignof__(struct nft_expr)))); 871 }; 872 873 static inline struct nft_expr *nft_expr_first(const struct nft_rule *rule) 874 { 875 return (struct nft_expr *)&rule->data[0]; 876 } 877 878 static inline struct nft_expr *nft_expr_next(const struct nft_expr *expr) 879 { 880 return ((void *)expr) + expr->ops->size; 881 } 882 883 static inline struct nft_expr *nft_expr_last(const struct nft_rule *rule) 884 { 885 return (struct nft_expr *)&rule->data[rule->dlen]; 886 } 887 888 static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule) 889 { 890 return (void *)&rule->data[rule->dlen]; 891 } 892 893 static inline void nft_set_elem_update_expr(const struct nft_set_ext *ext, 894 struct nft_regs *regs, 895 const struct nft_pktinfo *pkt) 896 { 897 struct nft_expr *expr; 898 899 if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPR)) { 900 expr = nft_set_ext_expr(ext); 901 expr->ops->eval(expr, regs, pkt); 902 } 903 } 904 905 /* 906 * The last pointer isn't really necessary, but the compiler isn't able to 907 * determine that the result of nft_expr_last() is always the same since it 908 * can't assume that the dlen value wasn't changed within calls in the loop. 909 */ 910 #define nft_rule_for_each_expr(expr, last, rule) \ 911 for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \ 912 (expr) != (last); \ 913 (expr) = nft_expr_next(expr)) 914 915 enum nft_chain_flags { 916 NFT_BASE_CHAIN = 0x1, 917 NFT_CHAIN_HW_OFFLOAD = 0x2, 918 }; 919 920 #define NFT_CHAIN_POLICY_UNSET U8_MAX 921 922 /** 923 * struct nft_chain - nf_tables chain 924 * 925 * @rules: list of rules in the chain 926 * @list: used internally 927 * @rhlhead: used internally 928 * @table: table that this chain belongs to 929 * @handle: chain handle 930 * @use: number of jump references to this chain 931 * @flags: bitmask of enum nft_chain_flags 932 * @name: name of the chain 933 */ 934 struct nft_chain { 935 struct nft_rule *__rcu *rules_gen_0; 936 struct nft_rule *__rcu *rules_gen_1; 937 struct list_head rules; 938 struct list_head list; 939 struct rhlist_head rhlhead; 940 struct nft_table *table; 941 u64 handle; 942 u32 use; 943 u8 flags:6, 944 genmask:2; 945 char *name; 946 947 /* Only used during control plane commit phase: */ 948 struct nft_rule **rules_next; 949 }; 950 951 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain); 952 953 enum nft_chain_types { 954 NFT_CHAIN_T_DEFAULT = 0, 955 NFT_CHAIN_T_ROUTE, 956 NFT_CHAIN_T_NAT, 957 NFT_CHAIN_T_MAX 958 }; 959 960 /** 961 * struct nft_chain_type - nf_tables chain type info 962 * 963 * @name: name of the type 964 * @type: numeric identifier 965 * @family: address family 966 * @owner: module owner 967 * @hook_mask: mask of valid hooks 968 * @hooks: array of hook functions 969 * @ops_register: base chain register function 970 * @ops_unregister: base chain unregister function 971 */ 972 struct nft_chain_type { 973 const char *name; 974 enum nft_chain_types type; 975 int family; 976 struct module *owner; 977 unsigned int hook_mask; 978 nf_hookfn *hooks[NF_MAX_HOOKS]; 979 int (*ops_register)(struct net *net, const struct nf_hook_ops *ops); 980 void (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops); 981 }; 982 983 int nft_chain_validate_dependency(const struct nft_chain *chain, 984 enum nft_chain_types type); 985 int nft_chain_validate_hooks(const struct nft_chain *chain, 986 unsigned int hook_flags); 987 988 struct nft_stats { 989 u64 bytes; 990 u64 pkts; 991 struct u64_stats_sync syncp; 992 }; 993 994 struct nft_hook { 995 struct list_head list; 996 struct nf_hook_ops ops; 997 struct rcu_head rcu; 998 }; 999 1000 /** 1001 * struct nft_base_chain - nf_tables base chain 1002 * 1003 * @ops: netfilter hook ops 1004 * @hook_list: list of netfilter hooks (for NFPROTO_NETDEV family) 1005 * @type: chain type 1006 * @policy: default policy 1007 * @stats: per-cpu chain stats 1008 * @chain: the chain 1009 * @flow_block: flow block (for hardware offload) 1010 */ 1011 struct nft_base_chain { 1012 struct nf_hook_ops ops; 1013 struct list_head hook_list; 1014 const struct nft_chain_type *type; 1015 u8 policy; 1016 u8 flags; 1017 struct nft_stats __percpu *stats; 1018 struct nft_chain chain; 1019 struct flow_block flow_block; 1020 }; 1021 1022 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain) 1023 { 1024 return container_of(chain, struct nft_base_chain, chain); 1025 } 1026 1027 static inline bool nft_is_base_chain(const struct nft_chain *chain) 1028 { 1029 return chain->flags & NFT_BASE_CHAIN; 1030 } 1031 1032 int __nft_release_basechain(struct nft_ctx *ctx); 1033 1034 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv); 1035 1036 /** 1037 * struct nft_table - nf_tables table 1038 * 1039 * @list: used internally 1040 * @chains_ht: chains in the table 1041 * @chains: same, for stable walks 1042 * @sets: sets in the table 1043 * @objects: stateful objects in the table 1044 * @flowtables: flow tables in the table 1045 * @hgenerator: handle generator state 1046 * @handle: table handle 1047 * @use: number of chain references to this table 1048 * @flags: table flag (see enum nft_table_flags) 1049 * @genmask: generation mask 1050 * @afinfo: address family info 1051 * @name: name of the table 1052 */ 1053 struct nft_table { 1054 struct list_head list; 1055 struct rhltable chains_ht; 1056 struct list_head chains; 1057 struct list_head sets; 1058 struct list_head objects; 1059 struct list_head flowtables; 1060 u64 hgenerator; 1061 u64 handle; 1062 u32 use; 1063 u16 family:6, 1064 flags:8, 1065 genmask:2; 1066 char *name; 1067 }; 1068 1069 void nft_register_chain_type(const struct nft_chain_type *); 1070 void nft_unregister_chain_type(const struct nft_chain_type *); 1071 1072 int nft_register_expr(struct nft_expr_type *); 1073 void nft_unregister_expr(struct nft_expr_type *); 1074 1075 int nft_verdict_dump(struct sk_buff *skb, int type, 1076 const struct nft_verdict *v); 1077 1078 /** 1079 * struct nft_object_hash_key - key to lookup nft_object 1080 * 1081 * @name: name of the stateful object to look up 1082 * @table: table the object belongs to 1083 */ 1084 struct nft_object_hash_key { 1085 const char *name; 1086 const struct nft_table *table; 1087 }; 1088 1089 /** 1090 * struct nft_object - nf_tables stateful object 1091 * 1092 * @list: table stateful object list node 1093 * @key: keys that identify this object 1094 * @rhlhead: nft_objname_ht node 1095 * @genmask: generation mask 1096 * @use: number of references to this stateful object 1097 * @handle: unique object handle 1098 * @ops: object operations 1099 * @data: object data, layout depends on type 1100 */ 1101 struct nft_object { 1102 struct list_head list; 1103 struct rhlist_head rhlhead; 1104 struct nft_object_hash_key key; 1105 u32 genmask:2, 1106 use:30; 1107 u64 handle; 1108 /* runtime data below here */ 1109 const struct nft_object_ops *ops ____cacheline_aligned; 1110 unsigned char data[] 1111 __attribute__((aligned(__alignof__(u64)))); 1112 }; 1113 1114 static inline void *nft_obj_data(const struct nft_object *obj) 1115 { 1116 return (void *)obj->data; 1117 } 1118 1119 #define nft_expr_obj(expr) *((struct nft_object **)nft_expr_priv(expr)) 1120 1121 struct nft_object *nft_obj_lookup(const struct net *net, 1122 const struct nft_table *table, 1123 const struct nlattr *nla, u32 objtype, 1124 u8 genmask); 1125 1126 void nft_obj_notify(struct net *net, const struct nft_table *table, 1127 struct nft_object *obj, u32 portid, u32 seq, 1128 int event, int family, int report, gfp_t gfp); 1129 1130 /** 1131 * struct nft_object_type - stateful object type 1132 * 1133 * @select_ops: function to select nft_object_ops 1134 * @ops: default ops, used when no select_ops functions is present 1135 * @list: list node in list of object types 1136 * @type: stateful object numeric type 1137 * @owner: module owner 1138 * @maxattr: maximum netlink attribute 1139 * @policy: netlink attribute policy 1140 */ 1141 struct nft_object_type { 1142 const struct nft_object_ops *(*select_ops)(const struct nft_ctx *, 1143 const struct nlattr * const tb[]); 1144 const struct nft_object_ops *ops; 1145 struct list_head list; 1146 u32 type; 1147 unsigned int maxattr; 1148 struct module *owner; 1149 const struct nla_policy *policy; 1150 }; 1151 1152 /** 1153 * struct nft_object_ops - stateful object operations 1154 * 1155 * @eval: stateful object evaluation function 1156 * @size: stateful object size 1157 * @init: initialize object from netlink attributes 1158 * @destroy: release existing stateful object 1159 * @dump: netlink dump stateful object 1160 * @update: update stateful object 1161 */ 1162 struct nft_object_ops { 1163 void (*eval)(struct nft_object *obj, 1164 struct nft_regs *regs, 1165 const struct nft_pktinfo *pkt); 1166 unsigned int size; 1167 int (*init)(const struct nft_ctx *ctx, 1168 const struct nlattr *const tb[], 1169 struct nft_object *obj); 1170 void (*destroy)(const struct nft_ctx *ctx, 1171 struct nft_object *obj); 1172 int (*dump)(struct sk_buff *skb, 1173 struct nft_object *obj, 1174 bool reset); 1175 void (*update)(struct nft_object *obj, 1176 struct nft_object *newobj); 1177 const struct nft_object_type *type; 1178 }; 1179 1180 int nft_register_obj(struct nft_object_type *obj_type); 1181 void nft_unregister_obj(struct nft_object_type *obj_type); 1182 1183 #define NFT_NETDEVICE_MAX 256 1184 1185 /** 1186 * struct nft_flowtable - nf_tables flow table 1187 * 1188 * @list: flow table list node in table list 1189 * @table: the table the flow table is contained in 1190 * @name: name of this flow table 1191 * @hooknum: hook number 1192 * @ops_len: number of hooks in array 1193 * @genmask: generation mask 1194 * @use: number of references to this flow table 1195 * @handle: unique object handle 1196 * @dev_name: array of device names 1197 * @data: rhashtable and garbage collector 1198 * @ops: array of hooks 1199 */ 1200 struct nft_flowtable { 1201 struct list_head list; 1202 struct nft_table *table; 1203 char *name; 1204 int hooknum; 1205 int ops_len; 1206 u32 genmask:2, 1207 use:30; 1208 u64 handle; 1209 /* runtime data below here */ 1210 struct list_head hook_list ____cacheline_aligned; 1211 struct nf_flowtable data; 1212 }; 1213 1214 struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table, 1215 const struct nlattr *nla, 1216 u8 genmask); 1217 1218 void nf_tables_deactivate_flowtable(const struct nft_ctx *ctx, 1219 struct nft_flowtable *flowtable, 1220 enum nft_trans_phase phase); 1221 1222 void nft_register_flowtable_type(struct nf_flowtable_type *type); 1223 void nft_unregister_flowtable_type(struct nf_flowtable_type *type); 1224 1225 /** 1226 * struct nft_traceinfo - nft tracing information and state 1227 * 1228 * @pkt: pktinfo currently processed 1229 * @basechain: base chain currently processed 1230 * @chain: chain currently processed 1231 * @rule: rule that was evaluated 1232 * @verdict: verdict given by rule 1233 * @type: event type (enum nft_trace_types) 1234 * @packet_dumped: packet headers sent in a previous traceinfo message 1235 * @trace: other struct members are initialised 1236 */ 1237 struct nft_traceinfo { 1238 const struct nft_pktinfo *pkt; 1239 const struct nft_base_chain *basechain; 1240 const struct nft_chain *chain; 1241 const struct nft_rule *rule; 1242 const struct nft_verdict *verdict; 1243 enum nft_trace_types type; 1244 bool packet_dumped; 1245 bool trace; 1246 }; 1247 1248 void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt, 1249 const struct nft_verdict *verdict, 1250 const struct nft_chain *basechain); 1251 1252 void nft_trace_notify(struct nft_traceinfo *info); 1253 1254 #define MODULE_ALIAS_NFT_CHAIN(family, name) \ 1255 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name) 1256 1257 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \ 1258 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name) 1259 1260 #define MODULE_ALIAS_NFT_EXPR(name) \ 1261 MODULE_ALIAS("nft-expr-" name) 1262 1263 #define MODULE_ALIAS_NFT_OBJ(type) \ 1264 MODULE_ALIAS("nft-obj-" __stringify(type)) 1265 1266 #if IS_ENABLED(CONFIG_NF_TABLES) 1267 1268 /* 1269 * The gencursor defines two generations, the currently active and the 1270 * next one. Objects contain a bitmask of 2 bits specifying the generations 1271 * they're active in. A set bit means they're inactive in the generation 1272 * represented by that bit. 1273 * 1274 * New objects start out as inactive in the current and active in the 1275 * next generation. When committing the ruleset the bitmask is cleared, 1276 * meaning they're active in all generations. When removing an object, 1277 * it is set inactive in the next generation. After committing the ruleset, 1278 * the objects are removed. 1279 */ 1280 static inline unsigned int nft_gencursor_next(const struct net *net) 1281 { 1282 return net->nft.gencursor + 1 == 1 ? 1 : 0; 1283 } 1284 1285 static inline u8 nft_genmask_next(const struct net *net) 1286 { 1287 return 1 << nft_gencursor_next(net); 1288 } 1289 1290 static inline u8 nft_genmask_cur(const struct net *net) 1291 { 1292 /* Use READ_ONCE() to prevent refetching the value for atomicity */ 1293 return 1 << READ_ONCE(net->nft.gencursor); 1294 } 1295 1296 #define NFT_GENMASK_ANY ((1 << 0) | (1 << 1)) 1297 1298 /* 1299 * Generic transaction helpers 1300 */ 1301 1302 /* Check if this object is currently active. */ 1303 #define nft_is_active(__net, __obj) \ 1304 (((__obj)->genmask & nft_genmask_cur(__net)) == 0) 1305 1306 /* Check if this object is active in the next generation. */ 1307 #define nft_is_active_next(__net, __obj) \ 1308 (((__obj)->genmask & nft_genmask_next(__net)) == 0) 1309 1310 /* This object becomes active in the next generation. */ 1311 #define nft_activate_next(__net, __obj) \ 1312 (__obj)->genmask = nft_genmask_cur(__net) 1313 1314 /* This object becomes inactive in the next generation. */ 1315 #define nft_deactivate_next(__net, __obj) \ 1316 (__obj)->genmask = nft_genmask_next(__net) 1317 1318 /* After committing the ruleset, clear the stale generation bit. */ 1319 #define nft_clear(__net, __obj) \ 1320 (__obj)->genmask &= ~nft_genmask_next(__net) 1321 #define nft_active_genmask(__obj, __genmask) \ 1322 !((__obj)->genmask & __genmask) 1323 1324 /* 1325 * Set element transaction helpers 1326 */ 1327 1328 static inline bool nft_set_elem_active(const struct nft_set_ext *ext, 1329 u8 genmask) 1330 { 1331 return !(ext->genmask & genmask); 1332 } 1333 1334 static inline void nft_set_elem_change_active(const struct net *net, 1335 const struct nft_set *set, 1336 struct nft_set_ext *ext) 1337 { 1338 ext->genmask ^= nft_genmask_next(net); 1339 } 1340 1341 #endif /* IS_ENABLED(CONFIG_NF_TABLES) */ 1342 1343 /* 1344 * We use a free bit in the genmask field to indicate the element 1345 * is busy, meaning it is currently being processed either by 1346 * the netlink API or GC. 1347 * 1348 * Even though the genmask is only a single byte wide, this works 1349 * because the extension structure if fully constant once initialized, 1350 * so there are no non-atomic write accesses unless it is already 1351 * marked busy. 1352 */ 1353 #define NFT_SET_ELEM_BUSY_MASK (1 << 2) 1354 1355 #if defined(__LITTLE_ENDIAN_BITFIELD) 1356 #define NFT_SET_ELEM_BUSY_BIT 2 1357 #elif defined(__BIG_ENDIAN_BITFIELD) 1358 #define NFT_SET_ELEM_BUSY_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2) 1359 #else 1360 #error 1361 #endif 1362 1363 static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext) 1364 { 1365 unsigned long *word = (unsigned long *)ext; 1366 1367 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0); 1368 return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word); 1369 } 1370 1371 static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext) 1372 { 1373 unsigned long *word = (unsigned long *)ext; 1374 1375 clear_bit(NFT_SET_ELEM_BUSY_BIT, word); 1376 } 1377 1378 /** 1379 * struct nft_trans - nf_tables object update in transaction 1380 * 1381 * @list: used internally 1382 * @msg_type: message type 1383 * @put_net: ctx->net needs to be put 1384 * @ctx: transaction context 1385 * @data: internal information related to the transaction 1386 */ 1387 struct nft_trans { 1388 struct list_head list; 1389 int msg_type; 1390 bool put_net; 1391 struct nft_ctx ctx; 1392 char data[]; 1393 }; 1394 1395 struct nft_trans_rule { 1396 struct nft_rule *rule; 1397 struct nft_flow_rule *flow; 1398 u32 rule_id; 1399 }; 1400 1401 #define nft_trans_rule(trans) \ 1402 (((struct nft_trans_rule *)trans->data)->rule) 1403 #define nft_trans_flow_rule(trans) \ 1404 (((struct nft_trans_rule *)trans->data)->flow) 1405 #define nft_trans_rule_id(trans) \ 1406 (((struct nft_trans_rule *)trans->data)->rule_id) 1407 1408 struct nft_trans_set { 1409 struct nft_set *set; 1410 u32 set_id; 1411 bool bound; 1412 }; 1413 1414 #define nft_trans_set(trans) \ 1415 (((struct nft_trans_set *)trans->data)->set) 1416 #define nft_trans_set_id(trans) \ 1417 (((struct nft_trans_set *)trans->data)->set_id) 1418 #define nft_trans_set_bound(trans) \ 1419 (((struct nft_trans_set *)trans->data)->bound) 1420 1421 struct nft_trans_chain { 1422 bool update; 1423 char *name; 1424 struct nft_stats __percpu *stats; 1425 u8 policy; 1426 }; 1427 1428 #define nft_trans_chain_update(trans) \ 1429 (((struct nft_trans_chain *)trans->data)->update) 1430 #define nft_trans_chain_name(trans) \ 1431 (((struct nft_trans_chain *)trans->data)->name) 1432 #define nft_trans_chain_stats(trans) \ 1433 (((struct nft_trans_chain *)trans->data)->stats) 1434 #define nft_trans_chain_policy(trans) \ 1435 (((struct nft_trans_chain *)trans->data)->policy) 1436 1437 struct nft_trans_table { 1438 bool update; 1439 bool enable; 1440 }; 1441 1442 #define nft_trans_table_update(trans) \ 1443 (((struct nft_trans_table *)trans->data)->update) 1444 #define nft_trans_table_enable(trans) \ 1445 (((struct nft_trans_table *)trans->data)->enable) 1446 1447 struct nft_trans_elem { 1448 struct nft_set *set; 1449 struct nft_set_elem elem; 1450 bool bound; 1451 }; 1452 1453 #define nft_trans_elem_set(trans) \ 1454 (((struct nft_trans_elem *)trans->data)->set) 1455 #define nft_trans_elem(trans) \ 1456 (((struct nft_trans_elem *)trans->data)->elem) 1457 #define nft_trans_elem_set_bound(trans) \ 1458 (((struct nft_trans_elem *)trans->data)->bound) 1459 1460 struct nft_trans_obj { 1461 struct nft_object *obj; 1462 struct nft_object *newobj; 1463 bool update; 1464 }; 1465 1466 #define nft_trans_obj(trans) \ 1467 (((struct nft_trans_obj *)trans->data)->obj) 1468 #define nft_trans_obj_newobj(trans) \ 1469 (((struct nft_trans_obj *)trans->data)->newobj) 1470 #define nft_trans_obj_update(trans) \ 1471 (((struct nft_trans_obj *)trans->data)->update) 1472 1473 struct nft_trans_flowtable { 1474 struct nft_flowtable *flowtable; 1475 }; 1476 1477 #define nft_trans_flowtable(trans) \ 1478 (((struct nft_trans_flowtable *)trans->data)->flowtable) 1479 1480 int __init nft_chain_filter_init(void); 1481 void nft_chain_filter_fini(void); 1482 1483 void __init nft_chain_route_init(void); 1484 void nft_chain_route_fini(void); 1485 #endif /* _NET_NF_TABLES_H */ 1486