Skip to content

Commit ffcddca

Browse files
committed
Merge tag 'nf-next-23-04-22' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next
Pablo Neira Ayuso says: ==================== Netfilter/IPVS updates for net-next 1) Reduce jumpstack footprint: Stash chain in last rule marker in blob for tracing. Remove last rule and chain from jumpstack. From Florian Westphal. 2) nf_tables validates all tables before committing the new rules. Unfortunately, this has two drawbacks: - Since addition of the transaction mutex pernet state gets written to outside of the locked section from the cleanup callback, this is wrong so do this cleanup directly after table has passed all checks. - Revalidate tables that saw no changes. This can be avoided by keeping the validation state per table, not per netns. From Florian Westphal. 3) Get rid of a few redundant pointers in the traceinfo structure. The three removed pointers are used in the expression evaluation loop, so gcc keeps them in registers. Passing them to the (inlined) helpers thus doesn't increase nft_do_chain text size, while stack is reduced by another 24 bytes on 64bit arches. From Florian Westphal. 4) IPVS cleanups in several ways without implementing any functional changes, aside from removing some debugging output: - Update width of source for ip_vs_sync_conn_options The operation is safe, use an annotation to describe it properly. - Consistently use array_size() in ip_vs_conn_init() It seems better to use helpers consistently. - Remove {Enter,Leave}Function. These seem to be well past their use-by date. - Correct spelling in comments. From Simon Horman. 5) Extended netlink error report for netdevice in flowtables and netdev/chains. Allow for incrementally add/delete devices to netdev basechain. Allow to create netdev chain without device. * tag 'nf-next-23-04-22' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next: netfilter: nf_tables: allow to create netdev chain without device netfilter: nf_tables: support for deleting devices in an existing netdev chain netfilter: nf_tables: support for adding new devices to an existing netdev chain netfilter: nf_tables: rename function to destroy hook list netfilter: nf_tables: do not send complete notification of deletions netfilter: nf_tables: extended netlink error reporting for netdevice ipvs: Correct spelling in comments ipvs: Remove {Enter,Leave}Function ipvs: Consistently use array_size() in ip_vs_conn_init() ipvs: Update width of source for ip_vs_sync_conn_options netfilter: nf_tables: do not store rule in traceinfo structure netfilter: nf_tables: do not store verdict in traceinfo structure netfilter: nf_tables: do not store pktinfo in traceinfo structure netfilter: nf_tables: remove unneeded conditional netfilter: nf_tables: make validation state per table netfilter: nf_tables: don't write table validation state without mutex netfilter: nf_tables: don't store chain address on jump netfilter: nf_tables: don't store address of last rule on jump netfilter: nf_tables: merge nft_rules_old structure and end of ruleblob marker ==================== Link: https://lore.kernel.org/r/20230421235021.216950-1-pablo@netfilter.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 2efb07b + 207296f commit ffcddca

12 files changed

Lines changed: 463 additions & 382 deletions

File tree

include/linux/netfilter/nfnetlink.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct nfnetlink_subsystem {
4545
int (*commit)(struct net *net, struct sk_buff *skb);
4646
int (*abort)(struct net *net, struct sk_buff *skb,
4747
enum nfnl_abort_action action);
48-
void (*cleanup)(struct net *net);
4948
bool (*valid_genid)(struct net *net, u32 genid);
5049
};
5150

include/net/ip_vs.h

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,26 +265,6 @@ static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
265265
pr_err(msg, ##__VA_ARGS__); \
266266
} while (0)
267267

268-
#ifdef CONFIG_IP_VS_DEBUG
269-
#define EnterFunction(level) \
270-
do { \
271-
if (level <= ip_vs_get_debug_level()) \
272-
printk(KERN_DEBUG \
273-
pr_fmt("Enter: %s, %s line %i\n"), \
274-
__func__, __FILE__, __LINE__); \
275-
} while (0)
276-
#define LeaveFunction(level) \
277-
do { \
278-
if (level <= ip_vs_get_debug_level()) \
279-
printk(KERN_DEBUG \
280-
pr_fmt("Leave: %s, %s line %i\n"), \
281-
__func__, __FILE__, __LINE__); \
282-
} while (0)
283-
#else
284-
#define EnterFunction(level) do {} while (0)
285-
#define LeaveFunction(level) do {} while (0)
286-
#endif
287-
288268
/* The port number of FTP service (in network order). */
289269
#define FTPPORT cpu_to_be16(21)
290270
#define FTPDATA cpu_to_be16(20)
@@ -604,7 +584,7 @@ struct ip_vs_conn {
604584
spinlock_t lock; /* lock for state transition */
605585
volatile __u16 state; /* state info */
606586
volatile __u16 old_state; /* old state, to be used for
607-
* state transition triggerd
587+
* state transition triggered
608588
* synchronization
609589
*/
610590
__u32 fwmark; /* Fire wall mark from skb */
@@ -630,8 +610,10 @@ struct ip_vs_conn {
630610
*/
631611
struct ip_vs_app *app; /* bound ip_vs_app object */
632612
void *app_data; /* Application private data */
633-
struct ip_vs_seq in_seq; /* incoming seq. struct */
634-
struct ip_vs_seq out_seq; /* outgoing seq. struct */
613+
struct_group(sync_conn_opt,
614+
struct ip_vs_seq in_seq; /* incoming seq. struct */
615+
struct ip_vs_seq out_seq; /* outgoing seq. struct */
616+
);
635617

636618
const struct ip_vs_pe *pe;
637619
char *pe_data;
@@ -653,7 +635,7 @@ struct ip_vs_service_user_kern {
653635
u16 protocol;
654636
union nf_inet_addr addr; /* virtual ip address */
655637
__be16 port;
656-
u32 fwmark; /* firwall mark of service */
638+
u32 fwmark; /* firewall mark of service */
657639

658640
/* virtual service options */
659641
char *sched_name;
@@ -1054,7 +1036,7 @@ struct netns_ipvs {
10541036
struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */
10551037
/* net name space ptr */
10561038
struct net *net; /* Needed by timer routines */
1057-
/* Number of heterogeneous destinations, needed becaus heterogeneous
1039+
/* Number of heterogeneous destinations, needed because heterogeneous
10581040
* are not supported when synchronization is enabled.
10591041
*/
10601042
unsigned int mixed_address_family_dests;

include/net/netfilter/nf_tables.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,18 @@ struct nft_rule_dp {
10461046
__attribute__((aligned(__alignof__(struct nft_expr))));
10471047
};
10481048

1049+
struct nft_rule_dp_last {
1050+
struct nft_rule_dp end; /* end of nft_rule_blob marker */
1051+
struct rcu_head h; /* call_rcu head */
1052+
struct nft_rule_blob *blob; /* ptr to free via call_rcu */
1053+
const struct nft_chain *chain; /* for nftables tracing */
1054+
};
1055+
1056+
static inline const struct nft_rule_dp *nft_rule_next(const struct nft_rule_dp *rule)
1057+
{
1058+
return (void *)rule + sizeof(*rule) + rule->dlen;
1059+
}
1060+
10491061
struct nft_rule_blob {
10501062
unsigned long size;
10511063
unsigned char data[]
@@ -1197,6 +1209,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
11971209
* @genmask: generation mask
11981210
* @afinfo: address family info
11991211
* @name: name of the table
1212+
* @validate_state: internal, set when transaction adds jumps
12001213
*/
12011214
struct nft_table {
12021215
struct list_head list;
@@ -1215,6 +1228,7 @@ struct nft_table {
12151228
char *name;
12161229
u16 udlen;
12171230
u8 *udata;
1231+
u8 validate_state;
12181232
};
12191233

12201234
static inline bool nft_table_has_owner(const struct nft_table *table)
@@ -1394,30 +1408,24 @@ void nft_unregister_flowtable_type(struct nf_flowtable_type *type);
13941408
* @type: event type (enum nft_trace_types)
13951409
* @skbid: hash of skb to be used as trace id
13961410
* @packet_dumped: packet headers sent in a previous traceinfo message
1397-
* @pkt: pktinfo currently processed
13981411
* @basechain: base chain currently processed
1399-
* @chain: chain currently processed
1400-
* @rule: rule that was evaluated
1401-
* @verdict: verdict given by rule
14021412
*/
14031413
struct nft_traceinfo {
14041414
bool trace;
14051415
bool nf_trace;
14061416
bool packet_dumped;
14071417
enum nft_trace_types type:8;
14081418
u32 skbid;
1409-
const struct nft_pktinfo *pkt;
14101419
const struct nft_base_chain *basechain;
1411-
const struct nft_chain *chain;
1412-
const struct nft_rule_dp *rule;
1413-
const struct nft_verdict *verdict;
14141420
};
14151421

14161422
void nft_trace_init(struct nft_traceinfo *info, const struct nft_pktinfo *pkt,
1417-
const struct nft_verdict *verdict,
14181423
const struct nft_chain *basechain);
14191424

1420-
void nft_trace_notify(struct nft_traceinfo *info);
1425+
void nft_trace_notify(const struct nft_pktinfo *pkt,
1426+
const struct nft_verdict *verdict,
1427+
const struct nft_rule_dp *rule,
1428+
struct nft_traceinfo *info);
14211429

14221430
#define MODULE_ALIAS_NFT_CHAIN(family, name) \
14231431
MODULE_ALIAS("nft-chain-" __stringify(family) "-" name)
@@ -1601,6 +1609,8 @@ struct nft_trans_chain {
16011609
struct nft_stats __percpu *stats;
16021610
u8 policy;
16031611
u32 chain_id;
1612+
struct nft_base_chain *basechain;
1613+
struct list_head hook_list;
16041614
};
16051615

16061616
#define nft_trans_chain_update(trans) \
@@ -1613,6 +1623,10 @@ struct nft_trans_chain {
16131623
(((struct nft_trans_chain *)trans->data)->policy)
16141624
#define nft_trans_chain_id(trans) \
16151625
(((struct nft_trans_chain *)trans->data)->chain_id)
1626+
#define nft_trans_basechain(trans) \
1627+
(((struct nft_trans_chain *)trans->data)->basechain)
1628+
#define nft_trans_chain_hooks(trans) \
1629+
(((struct nft_trans_chain *)trans->data)->hook_list)
16161630

16171631
struct nft_trans_table {
16181632
bool update;
@@ -1688,7 +1702,6 @@ struct nftables_pernet {
16881702
struct mutex commit_mutex;
16891703
u64 table_handle;
16901704
unsigned int base_seq;
1691-
u8 validate_state;
16921705
};
16931706

16941707
extern unsigned int nf_tables_net_id;

net/netfilter/ipvs/ip_vs_conn.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ void __net_exit ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs)
14811481

14821482
int __init ip_vs_conn_init(void)
14831483
{
1484+
size_t tab_array_size;
14841485
int idx;
14851486

14861487
/* Compute size and mask */
@@ -1494,8 +1495,9 @@ int __init ip_vs_conn_init(void)
14941495
/*
14951496
* Allocate the connection hash table and initialize its list heads
14961497
*/
1497-
ip_vs_conn_tab = vmalloc(array_size(ip_vs_conn_tab_size,
1498-
sizeof(*ip_vs_conn_tab)));
1498+
tab_array_size = array_size(ip_vs_conn_tab_size,
1499+
sizeof(*ip_vs_conn_tab));
1500+
ip_vs_conn_tab = vmalloc(tab_array_size);
14991501
if (!ip_vs_conn_tab)
15001502
return -ENOMEM;
15011503

@@ -1508,10 +1510,8 @@ int __init ip_vs_conn_init(void)
15081510
return -ENOMEM;
15091511
}
15101512

1511-
pr_info("Connection hash table configured "
1512-
"(size=%d, memory=%ldKbytes)\n",
1513-
ip_vs_conn_tab_size,
1514-
(long)(ip_vs_conn_tab_size*sizeof(*ip_vs_conn_tab))/1024);
1513+
pr_info("Connection hash table configured (size=%d, memory=%zdKbytes)\n",
1514+
ip_vs_conn_tab_size, tab_array_size / 1024);
15151515
IP_VS_DBG(0, "Each connection entry needs %zd bytes at least\n",
15161516
sizeof(struct ip_vs_conn));
15171517

net/netfilter/ipvs/ip_vs_core.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
11401140
__be16 vport;
11411141
unsigned int flags;
11421142

1143-
EnterFunction(12);
11441143
vaddr = &svc->addr;
11451144
vport = svc->port;
11461145
daddr = &iph->saddr;
@@ -1208,7 +1207,6 @@ struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
12081207
IP_VS_DBG_ADDR(cp->af, &cp->vaddr), ntohs(cp->vport),
12091208
IP_VS_DBG_ADDR(cp->af, &cp->daddr), ntohs(cp->dport),
12101209
cp->flags, refcount_read(&cp->refcnt));
1211-
LeaveFunction(12);
12121210
return cp;
12131211
}
12141212

@@ -1316,13 +1314,11 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
13161314
ip_vs_update_conntrack(skb, cp, 0);
13171315
ip_vs_conn_put(cp);
13181316

1319-
LeaveFunction(11);
13201317
return NF_ACCEPT;
13211318

13221319
drop:
13231320
ip_vs_conn_put(cp);
13241321
kfree_skb(skb);
1325-
LeaveFunction(11);
13261322
return NF_STOLEN;
13271323
}
13281324

@@ -1341,8 +1337,6 @@ ip_vs_out_hook(void *priv, struct sk_buff *skb, const struct nf_hook_state *stat
13411337
int af = state->pf;
13421338
struct sock *sk;
13431339

1344-
EnterFunction(11);
1345-
13461340
/* Already marked as IPVS request or reply? */
13471341
if (skb->ipvs_property)
13481342
return NF_ACCEPT;
@@ -2365,7 +2359,6 @@ static void __net_exit __ip_vs_dev_cleanup_batch(struct list_head *net_list)
23652359
struct netns_ipvs *ipvs;
23662360
struct net *net;
23672361

2368-
EnterFunction(2);
23692362
list_for_each_entry(net, net_list, exit_list) {
23702363
ipvs = net_ipvs(net);
23712364
ip_vs_unregister_hooks(ipvs, AF_INET);
@@ -2374,7 +2367,6 @@ static void __net_exit __ip_vs_dev_cleanup_batch(struct list_head *net_list)
23742367
smp_wmb();
23752368
ip_vs_sync_net_cleanup(ipvs);
23762369
}
2377-
LeaveFunction(2);
23782370
}
23792371

23802372
static struct pernet_operations ipvs_core_ops = {

net/netfilter/ipvs/ip_vs_ctl.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,8 +1061,6 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
10611061
unsigned int atype;
10621062
int ret;
10631063

1064-
EnterFunction(2);
1065-
10661064
#ifdef CONFIG_IP_VS_IPV6
10671065
if (udest->af == AF_INET6) {
10681066
atype = ipv6_addr_type(&udest->addr.in6);
@@ -1111,7 +1109,6 @@ ip_vs_new_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
11111109
spin_lock_init(&dest->dst_lock);
11121110
__ip_vs_update_dest(svc, dest, udest, 1);
11131111

1114-
LeaveFunction(2);
11151112
return 0;
11161113

11171114
err_stats:
@@ -1134,8 +1131,6 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
11341131
__be16 dport = udest->port;
11351132
int ret;
11361133

1137-
EnterFunction(2);
1138-
11391134
if (udest->weight < 0) {
11401135
pr_err("%s(): server weight less than zero\n", __func__);
11411136
return -ERANGE;
@@ -1183,7 +1178,7 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
11831178

11841179
ret = ip_vs_start_estimator(svc->ipvs, &dest->stats);
11851180
if (ret < 0)
1186-
goto err;
1181+
return ret;
11871182
__ip_vs_update_dest(svc, dest, udest, 1);
11881183
} else {
11891184
/*
@@ -1192,9 +1187,6 @@ ip_vs_add_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
11921187
ret = ip_vs_new_dest(svc, udest);
11931188
}
11941189

1195-
err:
1196-
LeaveFunction(2);
1197-
11981190
return ret;
11991191
}
12001192

@@ -1209,8 +1201,6 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
12091201
union nf_inet_addr daddr;
12101202
__be16 dport = udest->port;
12111203

1212-
EnterFunction(2);
1213-
12141204
if (udest->weight < 0) {
12151205
pr_err("%s(): server weight less than zero\n", __func__);
12161206
return -ERANGE;
@@ -1242,7 +1232,6 @@ ip_vs_edit_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
12421232
}
12431233

12441234
__ip_vs_update_dest(svc, dest, udest, 0);
1245-
LeaveFunction(2);
12461235

12471236
return 0;
12481237
}
@@ -1317,8 +1306,6 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
13171306
struct ip_vs_dest *dest;
13181307
__be16 dport = udest->port;
13191308

1320-
EnterFunction(2);
1321-
13221309
/* We use function that requires RCU lock */
13231310
rcu_read_lock();
13241311
dest = ip_vs_lookup_dest(svc, udest->af, &udest->addr, dport);
@@ -1339,8 +1326,6 @@ ip_vs_del_dest(struct ip_vs_service *svc, struct ip_vs_dest_user_kern *udest)
13391326
*/
13401327
__ip_vs_del_dest(svc->ipvs, dest, false);
13411328

1342-
LeaveFunction(2);
1343-
13441329
return 0;
13451330
}
13461331

@@ -1746,15 +1731,13 @@ void ip_vs_service_nets_cleanup(struct list_head *net_list)
17461731
struct netns_ipvs *ipvs;
17471732
struct net *net;
17481733

1749-
EnterFunction(2);
17501734
/* Check for "full" addressed entries */
17511735
mutex_lock(&__ip_vs_mutex);
17521736
list_for_each_entry(net, net_list, exit_list) {
17531737
ipvs = net_ipvs(net);
17541738
ip_vs_flush(ipvs, true);
17551739
}
17561740
mutex_unlock(&__ip_vs_mutex);
1757-
LeaveFunction(2);
17581741
}
17591742

17601743
/* Put all references for device (dst_cache) */
@@ -1792,7 +1775,6 @@ static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
17921775
if (event != NETDEV_DOWN || !ipvs)
17931776
return NOTIFY_DONE;
17941777
IP_VS_DBG(3, "%s() dev=%s\n", __func__, dev->name);
1795-
EnterFunction(2);
17961778
mutex_lock(&__ip_vs_mutex);
17971779
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
17981780
hlist_for_each_entry(svc, &ip_vs_svc_table[idx], s_list) {
@@ -1821,7 +1803,6 @@ static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
18211803
}
18221804
spin_unlock_bh(&ipvs->dest_trash_lock);
18231805
mutex_unlock(&__ip_vs_mutex);
1824-
LeaveFunction(2);
18251806
return NOTIFY_DONE;
18261807
}
18271808

@@ -4537,8 +4518,6 @@ int __init ip_vs_control_init(void)
45374518
int idx;
45384519
int ret;
45394520

4540-
EnterFunction(2);
4541-
45424521
/* Initialize svc_table, ip_vs_svc_fwm_table */
45434522
for (idx = 0; idx < IP_VS_SVC_TAB_SIZE; idx++) {
45444523
INIT_HLIST_HEAD(&ip_vs_svc_table[idx]);
@@ -4551,15 +4530,12 @@ int __init ip_vs_control_init(void)
45514530
if (ret < 0)
45524531
return ret;
45534532

4554-
LeaveFunction(2);
45554533
return 0;
45564534
}
45574535

45584536

45594537
void ip_vs_control_cleanup(void)
45604538
{
4561-
EnterFunction(2);
45624539
unregister_netdevice_notifier(&ip_vs_dst_notifier);
45634540
/* relying on common rcu_barrier() in ip_vs_cleanup() */
4564-
LeaveFunction(2);
45654541
}

0 commit comments

Comments
 (0)