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 /* 894 * The last pointer isn't really necessary, but the compiler isn't able to 895 * determine that the result of nft_expr_last() is always the same since it 896 * can't assume that the dlen value wasn't changed within calls in the loop. 897 */ 898 #define nft_rule_for_each_expr(expr, last, rule) \ 899 for ((expr) = nft_expr_first(rule), (last) = nft_expr_last(rule); \ 900 (expr) != (last); \ 901 (expr) = nft_expr_next(expr)) 902 903 enum nft_chain_flags { 904 NFT_BASE_CHAIN = 0x1, 905 NFT_CHAIN_HW_OFFLOAD = 0x2, 906 }; 907 908 #define NFT_CHAIN_POLICY_UNSET U8_MAX 909 910 /** 911 * struct nft_chain - nf_tables chain 912 * 913 * @rules: list of rules in the chain 914 * @list: used internally 915 * @rhlhead: used internally 916 * @table: table that this chain belongs to 917 * @handle: chain handle 918 * @use: number of jump references to this chain 919 * @flags: bitmask of enum nft_chain_flags 920 * @name: name of the chain 921 */ 922 struct nft_chain { 923 struct nft_rule *__rcu *rules_gen_0; 924 struct nft_rule *__rcu *rules_gen_1; 925 struct list_head rules; 926 struct list_head list; 927 struct rhlist_head rhlhead; 928 struct nft_table *table; 929 u64 handle; 930 u32 use; 931 u8 flags:6, 932 genmask:2; 933 char *name; 934 935 /* Only used during control plane commit phase: */ 936 struct nft_rule **rules_next; 937 }; 938 939 int nft_chain_validate(const struct nft_ctx *ctx, const struct nft_chain *chain); 940 941 enum nft_chain_types { 942 NFT_CHAIN_T_DEFAULT = 0, 943 NFT_CHAIN_T_ROUTE, 944 NFT_CHAIN_T_NAT, 945 NFT_CHAIN_T_MAX 946 }; 947 948 /** 949 * struct nft_chain_type - nf_tables chain type info 950 * 951 * @name: name of the type 952 * @type: numeric identifier 953 * @family: address family 954 * @owner: module owner 955 * @hook_mask: mask of valid hooks 956 * @hooks: array of hook functions 957 * @ops_register: base chain register function 958 * @ops_unregister: base chain unregister function 959 */ 960 struct nft_chain_type { 961 const char *name; 962 enum nft_chain_types type; 963 int family; 964 struct module *owner; 965 unsigned int hook_mask; 966 nf_hookfn *hooks[NF_MAX_HOOKS]; 967 int (*ops_register)(struct net *net, const struct nf_hook_ops *ops); 968 void (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops); 969 }; 970 971 int nft_chain_validate_dependency(const struct nft_chain *chain, 972 enum nft_chain_types type); 973 int nft_chain_validate_hooks(const struct nft_chain *chain, 974 unsigned int hook_flags); 975 976 struct nft_stats { 977 u64 bytes; 978 u64 pkts; 979 struct u64_stats_sync syncp; 980 }; 981 982 struct nft_hook { 983 struct list_head list; 984 struct nf_hook_ops ops; 985 struct rcu_head rcu; 986 }; 987 988 /** 989 * struct nft_base_chain - nf_tables base chain 990 * 991 * @ops: netfilter hook ops 992 * @hook_list: list of netfilter hooks (for NFPROTO_NETDEV family) 993 * @type: chain type 994 * @policy: default policy 995 * @stats: per-cpu chain stats 996 * @chain: the chain 997 * @flow_block: flow block (for hardware offload) 998 */ 999 struct nft_base_chain { 1000 struct nf_hook_ops ops; 1001 struct list_head hook_list; 1002 const struct nft_chain_type *type; 1003 u8 policy; 1004 u8 flags; 1005 struct nft_stats __percpu *stats; 1006 struct nft_chain chain; 1007 struct flow_block flow_block; 1008 }; 1009 1010 static inline struct nft_base_chain *nft_base_chain(const struct nft_chain *chain) 1011 { 1012 return container_of(chain, struct nft_base_chain, chain); 1013 } 1014 1015 static inline bool nft_is_base_chain(const struct nft_chain *chain) 1016 { 1017 return chain->flags & NFT_BASE_CHAIN; 1018 } 1019 1020 int __nft_release_basechain(struct nft_ctx *ctx); 1021 1022 unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv); 1023 1024 /** 1025 * struct nft_table - nf_tables table 1026 * 1027 * @list: used internally 1028 * @chains_ht: chains in the table 1029 * @chains: same, for stable walks 1030 * @sets: sets in the table 1031 * @objects: stateful objects in the table 1032 * @flowtables: flow tables in the table 1033 * @hgenerator: handle generator state 1034 * @handle: table handle 1035 * @use: number of chain references to this table 1036 * @flags: table flag (see enum nft_table_flags) 1037 * @genmask: generation mask 1038 * @afinfo: address family info 1039 * @name: name of the table 1040 */ 1041 struct nft_table { 1042 struct list_head list; 1043 struct rhltable chains_ht; 1044 struct list_head chains; 1045 struct list_head sets; 1046 struct list_head objects; 1047 struct list_head flowtables; 1048 u64 hgenerator; 1049 u64 handle; 1050 u32 use; 1051 u16 family:6, 1052 flags:8, 1053 genmask:2; 1054 char *name; 1055 }; 1056 1057 void nft_register_chain_type(const struct nft_chain_type *); 1058 void nft_unregister_chain_type(const struct nft_chain_type *); 1059 1060 int nft_register_expr(struct nft_expr_type *); 1061 void nft_unregister_expr(struct nft_expr_type *); 1062 1063 int nft_verdict_dump(struct sk_buff *skb, int type, 1064 const struct nft_verdict *v); 1065 1066 /** 1067 * struct nft_object_hash_key - key to lookup nft_object 1068 * 1069 * @name: name of the stateful object to look up 1070 * @table: table the object belongs to 1071 */ 1072 struct nft_object_hash_key { 1073 const char *name; 1074 const struct nft_table *table; 1075 }; 1076 1077 /** 1078 * struct nft_object - nf_tables stateful object 1079 * 1080 * @list: table stateful object list node 1081 * @key: keys that identify this object 1082 * @rhlhead: nft_objname_ht node 1083 * @genmask: generation mask 1084 * @use: number of references to this stateful object 1085 * @handle: unique object handle 1086 * @ops: object operations 1087 * @data: object data, layout depends on type 1088 */ 1089 struct nft_object { 1090 struct list_head list; 1091 struct rhlist_head rhlhead; 1092 struct nft_object_hash_key key; 1093 u32 genmask:2, 1094 use:30; 1095 u64 handle; 1096 /* runtime data below here */ 1097 const struct nft_object_ops *ops ____cacheline_aligned; 1098 unsigned char data[] 1099 __attribute__((aligned(__alignof__(u64)))); 1100 }; 1101 1102 static inline void *nft_obj_data(const struct nft_object *obj) 1103 { 1104 return (void *)obj->data; 1105 } 1106 1107 #define nft_expr_obj(expr) *((struct nft_object **)nft_expr_priv(expr)) 1108 1109 struct nft_object *nft_obj_lookup(const struct net *net, 1110 const struct nft_table *table, 1111 const struct nlattr *nla, u32 objtype, 1112 u8 genmask); 1113 1114 void nft_obj_notify(struct net *net, const struct nft_table *table, 1115 struct nft_object *obj, u32 portid, u32 seq, 1116 int event, int family, int report, gfp_t gfp); 1117 1118 /** 1119 * struct nft_object_type - stateful object type 1120 * 1121 * @select_ops: function to select nft_object_ops 1122 * @ops: default ops, used when no select_ops functions is present 1123 * @list: list node in list of object types 1124 * @type: stateful object numeric type 1125 * @owner: module owner 1126 * @maxattr: maximum netlink attribute 1127 * @policy: netlink attribute policy 1128 */ 1129 struct nft_object_type { 1130 const struct nft_object_ops *(*select_ops)(const struct nft_ctx *, 1131 const struct nlattr * const tb[]); 1132 const struct nft_object_ops *ops; 1133 struct list_head list; 1134 u32 type; 1135 unsigned int maxattr; 1136 struct module *owner; 1137 const struct nla_policy *policy; 1138 }; 1139 1140 /** 1141 * struct nft_object_ops - stateful object operations 1142 * 1143 * @eval: stateful object evaluation function 1144 * @size: stateful object size 1145 * @init: initialize object from netlink attributes 1146 * @destroy: release existing stateful object 1147 * @dump: netlink dump stateful object 1148 * @update: update stateful object 1149 */ 1150 struct nft_object_ops { 1151 void (*eval)(struct nft_object *obj, 1152 struct nft_regs *regs, 1153 const struct nft_pktinfo *pkt); 1154 unsigned int size; 1155 int (*init)(const struct nft_ctx *ctx, 1156 const struct nlattr *const tb[], 1157 struct nft_object *obj); 1158 void (*destroy)(const struct nft_ctx *ctx, 1159 struct nft_object *obj); 1160 int (*dump)(struct sk_buff *skb, 1161 struct nft_object *obj, 1162 bool reset); 1163 void (*update)(struct nft_object *obj, 1164 struct nft_object *newobj); 1165 const struct nft_object_type *type; 1166 }; 1167 1168 int nft_register_obj(struct nft_object_type *obj_type); 1169 void nft_unregister_obj(struct nft_object_type *obj_type); 1170 1171 #define NFT_NETDEVICE_MAX 256 1172 1173 /** 1174 * struct nft_flowtable - nf_tables flow table 1175 * 1176 * @list: flow table list node in table list 1177 * @table: the table the flow table is contained in 1178 * @name: name of this flow table 1179 * @hooknum: hook number 1180 * @ops_len: number of hooks in array 1181 * @genmask: generation mask 1182 * @use: number of references to this flow table 1183 * @handle: unique object handle 1184 * @dev_name: array of device names 1185 * @data: rhashtable and garbage collector 1186 * @ops: array of hooks 1187 */ 1188 struct nft_flowtable { 1189 struct list_head list; 1190 struct nft_table *table; 1191 char *name; 1192 int hooknum; 1193 int ops_len; 1194 u32 genmask:2, 1195 use:30; 1196 u64 handle; 1197 /* runtime data below here */ 1198 struct list_head hook_list ____cacheline_aligned; 1199 struct nf_flowtable data; 1200 }; 1201 1202 struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table, 1203 const struct nlattr *nla, 1204 u8 genmask); 1205 1206 void nf_tables_deactivate_flowtable(const struct nft_ctx *ctx, 1207 struct nft_flowtable *flowtable, 1208 enum nft_trans_phase phase); 1209 1210 void nft_register_flowtable_type(struct nf_flowtable_type *type); 1211 void nft_unregister_flowtable_type(struct nf_flowtable_type *type); 1212 1213 /** 1214 * struct nft_traceinfo - nft tracing information and state 1215 * 1216 * @pkt: pktinfo currently processed 1217 * @basechain: base chain currently processed 1218 * @chain: chain currently processed 1219 * @rule: rule that was evaluated 1220 * @verdict: verdict given by rule 1221 * @type: event type (enum nft_trace_types) 1222 * @packet_dumped: packet headers sent in a previous traceinfo message 1223 * @trace: other struct members are initialised 1224 */ 1225 struct nft_traceinfo { 1226 const struct nft_pktinfo *pkt; 1227 const struct nft_base_chain *basechain; 1228 const struct nft_chain *chain; 1229 const struct nft_rule *rule; 1230 const struct nft_verdict *verdict; 1231 enum nft_trace_types type; 1232 bool packet_dumped; 1233 bool trace; 1234 }; 1235 1236 void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt, 1237 const struct nft_verdict *verdict, 1238 const struct nft_chain *basechain); 1239 1240 void nft_trace_notify(struct nft_traceinfo *info); 1241 1242 #define MODULE_ALIAS_NFT_CHAIN(family, name) \ 1243 MODULE_ALIAS("nft-chain-" __stringify(family) "-" name) 1244 1245 #define MODULE_ALIAS_NFT_AF_EXPR(family, name) \ 1246 MODULE_ALIAS("nft-expr-" __stringify(family) "-" name) 1247 1248 #define MODULE_ALIAS_NFT_EXPR(name) \ 1249 MODULE_ALIAS("nft-expr-" name) 1250 1251 #define MODULE_ALIAS_NFT_OBJ(type) \ 1252 MODULE_ALIAS("nft-obj-" __stringify(type)) 1253 1254 #if IS_ENABLED(CONFIG_NF_TABLES) 1255 1256 /* 1257 * The gencursor defines two generations, the currently active and the 1258 * next one. Objects contain a bitmask of 2 bits specifying the generations 1259 * they're active in. A set bit means they're inactive in the generation 1260 * represented by that bit. 1261 * 1262 * New objects start out as inactive in the current and active in the 1263 * next generation. When committing the ruleset the bitmask is cleared, 1264 * meaning they're active in all generations. When removing an object, 1265 * it is set inactive in the next generation. After committing the ruleset, 1266 * the objects are removed. 1267 */ 1268 static inline unsigned int nft_gencursor_next(const struct net *net) 1269 { 1270 return net->nft.gencursor + 1 == 1 ? 1 : 0; 1271 } 1272 1273 static inline u8 nft_genmask_next(const struct net *net) 1274 { 1275 return 1 << nft_gencursor_next(net); 1276 } 1277 1278 static inline u8 nft_genmask_cur(const struct net *net) 1279 { 1280 /* Use READ_ONCE() to prevent refetching the value for atomicity */ 1281 return 1 << READ_ONCE(net->nft.gencursor); 1282 } 1283 1284 #define NFT_GENMASK_ANY ((1 << 0) | (1 << 1)) 1285 1286 /* 1287 * Generic transaction helpers 1288 */ 1289 1290 /* Check if this object is currently active. */ 1291 #define nft_is_active(__net, __obj) \ 1292 (((__obj)->genmask & nft_genmask_cur(__net)) == 0) 1293 1294 /* Check if this object is active in the next generation. */ 1295 #define nft_is_active_next(__net, __obj) \ 1296 (((__obj)->genmask & nft_genmask_next(__net)) == 0) 1297 1298 /* This object becomes active in the next generation. */ 1299 #define nft_activate_next(__net, __obj) \ 1300 (__obj)->genmask = nft_genmask_cur(__net) 1301 1302 /* This object becomes inactive in the next generation. */ 1303 #define nft_deactivate_next(__net, __obj) \ 1304 (__obj)->genmask = nft_genmask_next(__net) 1305 1306 /* After committing the ruleset, clear the stale generation bit. */ 1307 #define nft_clear(__net, __obj) \ 1308 (__obj)->genmask &= ~nft_genmask_next(__net) 1309 #define nft_active_genmask(__obj, __genmask) \ 1310 !((__obj)->genmask & __genmask) 1311 1312 /* 1313 * Set element transaction helpers 1314 */ 1315 1316 static inline bool nft_set_elem_active(const struct nft_set_ext *ext, 1317 u8 genmask) 1318 { 1319 return !(ext->genmask & genmask); 1320 } 1321 1322 static inline void nft_set_elem_change_active(const struct net *net, 1323 const struct nft_set *set, 1324 struct nft_set_ext *ext) 1325 { 1326 ext->genmask ^= nft_genmask_next(net); 1327 } 1328 1329 #endif /* IS_ENABLED(CONFIG_NF_TABLES) */ 1330 1331 /* 1332 * We use a free bit in the genmask field to indicate the element 1333 * is busy, meaning it is currently being processed either by 1334 * the netlink API or GC. 1335 * 1336 * Even though the genmask is only a single byte wide, this works 1337 * because the extension structure if fully constant once initialized, 1338 * so there are no non-atomic write accesses unless it is already 1339 * marked busy. 1340 */ 1341 #define NFT_SET_ELEM_BUSY_MASK (1 << 2) 1342 1343 #if defined(__LITTLE_ENDIAN_BITFIELD) 1344 #define NFT_SET_ELEM_BUSY_BIT 2 1345 #elif defined(__BIG_ENDIAN_BITFIELD) 1346 #define NFT_SET_ELEM_BUSY_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2) 1347 #else 1348 #error 1349 #endif 1350 1351 static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext) 1352 { 1353 unsigned long *word = (unsigned long *)ext; 1354 1355 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0); 1356 return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word); 1357 } 1358 1359 static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext) 1360 { 1361 unsigned long *word = (unsigned long *)ext; 1362 1363 clear_bit(NFT_SET_ELEM_BUSY_BIT, word); 1364 } 1365 1366 /** 1367 * struct nft_trans - nf_tables object update in transaction 1368 * 1369 * @list: used internally 1370 * @msg_type: message type 1371 * @put_net: ctx->net needs to be put 1372 * @ctx: transaction context 1373 * @data: internal information related to the transaction 1374 */ 1375 struct nft_trans { 1376 struct list_head list; 1377 int msg_type; 1378 bool put_net; 1379 struct nft_ctx ctx; 1380 char data[]; 1381 }; 1382 1383 struct nft_trans_rule { 1384 struct nft_rule *rule; 1385 struct nft_flow_rule *flow; 1386 u32 rule_id; 1387 }; 1388 1389 #define nft_trans_rule(trans) \ 1390 (((struct nft_trans_rule *)trans->data)->rule) 1391 #define nft_trans_flow_rule(trans) \ 1392 (((struct nft_trans_rule *)trans->data)->flow) 1393 #define nft_trans_rule_id(trans) \ 1394 (((struct nft_trans_rule *)trans->data)->rule_id) 1395 1396 struct nft_trans_set { 1397 struct nft_set *set; 1398 u32 set_id; 1399 bool bound; 1400 }; 1401 1402 #define nft_trans_set(trans) \ 1403 (((struct nft_trans_set *)trans->data)->set) 1404 #define nft_trans_set_id(trans) \ 1405 (((struct nft_trans_set *)trans->data)->set_id) 1406 #define nft_trans_set_bound(trans) \ 1407 (((struct nft_trans_set *)trans->data)->bound) 1408 1409 struct nft_trans_chain { 1410 bool update; 1411 char *name; 1412 struct nft_stats __percpu *stats; 1413 u8 policy; 1414 }; 1415 1416 #define nft_trans_chain_update(trans) \ 1417 (((struct nft_trans_chain *)trans->data)->update) 1418 #define nft_trans_chain_name(trans) \ 1419 (((struct nft_trans_chain *)trans->data)->name) 1420 #define nft_trans_chain_stats(trans) \ 1421 (((struct nft_trans_chain *)trans->data)->stats) 1422 #define nft_trans_chain_policy(trans) \ 1423 (((struct nft_trans_chain *)trans->data)->policy) 1424 1425 struct nft_trans_table { 1426 bool update; 1427 bool enable; 1428 }; 1429 1430 #define nft_trans_table_update(trans) \ 1431 (((struct nft_trans_table *)trans->data)->update) 1432 #define nft_trans_table_enable(trans) \ 1433 (((struct nft_trans_table *)trans->data)->enable) 1434 1435 struct nft_trans_elem { 1436 struct nft_set *set; 1437 struct nft_set_elem elem; 1438 bool bound; 1439 }; 1440 1441 #define nft_trans_elem_set(trans) \ 1442 (((struct nft_trans_elem *)trans->data)->set) 1443 #define nft_trans_elem(trans) \ 1444 (((struct nft_trans_elem *)trans->data)->elem) 1445 #define nft_trans_elem_set_bound(trans) \ 1446 (((struct nft_trans_elem *)trans->data)->bound) 1447 1448 struct nft_trans_obj { 1449 struct nft_object *obj; 1450 struct nft_object *newobj; 1451 bool update; 1452 }; 1453 1454 #define nft_trans_obj(trans) \ 1455 (((struct nft_trans_obj *)trans->data)->obj) 1456 #define nft_trans_obj_newobj(trans) \ 1457 (((struct nft_trans_obj *)trans->data)->newobj) 1458 #define nft_trans_obj_update(trans) \ 1459 (((struct nft_trans_obj *)trans->data)->update) 1460 1461 struct nft_trans_flowtable { 1462 struct nft_flowtable *flowtable; 1463 }; 1464 1465 #define nft_trans_flowtable(trans) \ 1466 (((struct nft_trans_flowtable *)trans->data)->flowtable) 1467 1468 int __init nft_chain_filter_init(void); 1469 void nft_chain_filter_fini(void); 1470 1471 void __init nft_chain_route_init(void); 1472 void nft_chain_route_fini(void); 1473 #endif /* _NET_NF_TABLES_H */ 1474