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