batctl: add subcommand to limit number of learned objects
PATCH 1/1 batctl: add subcommand to limit number of learned objects
A malicious actor connected to the mesh network or the client interface could cause batman-adv to learn more and more objects (originators, neighbors, (Distributed) ARP table entries, bridge loop avoidance backbones/claims, ...). For each learned object, memory is used by batman-adv. The malicious actor could trigger an out-of-memory situation or cause slow-downs.
The limit subcommand can be used to configure limits for these automatically learned objects or to read the out the available object types.
If no parameter is given the current limits for remote learned objects are displayed. Otherwise the parameters are interpreted as pairs of limit name and value and are used to set the given limits. Limits which are not specified as parameter are left unmodified. A limit of 0 disables the limit for this object type.
--- Makefile | 1 + README.rst | 31 +++++++++++ batman_adv.h | 30 ++++++++++ event.c | 20 +++++++ genl_json.c | 20 +++++++ limit.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man/batctl.8 | 7 +++ netlink.c | 15 +++++ 8 files changed, 300 insertions(+)
Makefile +1 -0
@@ -59,6 +59,7 @@ $(eval $(call add_command,hardifs_json,y)) $(eval $(call add_command,hop_penalty,y)) $(eval $(call add_command,interface,y)) $(eval $(call add_command,isolation_mark,y)) +$(eval $(call add_command,limit,y)) $(eval $(call add_command,loglevel,y)) $(eval $(call add_command,mcast_flags,y)) $(eval $(call add_command,mcast_flags_json,y))
README.rst +31 -0
@@ -626,6 +626,37 @@ Usage:: * Example 4: ``batctl mark 0x0f`` +batctl limit +------------ + +display or modify the limits for remote learned objects + +If no parameter is given the current limits are displayed. Otherwise the +parameters are interpreted as pairs of limit name and value and are used +to set the given limits. Limits which are not specified as parameter are +left unmodified. A limit of 0 disables the limit for this object type. + +Usage:: + + batctl limit|lt [limit value]... + +Example:: + + $ batctl limit + neighbors: 0 + originators: 0 + dat: 0 + bla_backbones: 0 + bla_claims: 0 + $ batctl limit neighbors 64 originators 128 + $ batctl limit + neighbors: 64 + originators: 128 + dat: 0 + bla_backbones: 0 + bla_claims: 0 + + batctl loglevel ---------------
batman_adv.h +30 -0
@@ -481,6 +481,36 @@ enum batadv_nl_attrs {*/ BATADV_ATTR_MULTICAST_FANOUT , +/** +* @BATADV_ATTR_NEIGH_MAX_LEARNED: defines the maximum number of neighbors +* which can be learned in parallel +*/ +BATADV_ATTR_NEIGH_MAX_LEARNED , + +/** +* @BATADV_ATTR_ORIG_MAX_LEARNED: defines the maximum number of originator +* which can be learned in parallel +*/ +BATADV_ATTR_ORIG_MAX_LEARNED , + +/** +* @BATADV_ATTR_DAT_MAX_LEARNED: defines the maximum number of DAT entries +* which can be learned in parallel +*/ +BATADV_ATTR_DAT_MAX_LEARNED , + +/** +* @BATADV_ATTR_BLA_BACKBONE_MAX_LEARNED: defines the maximum number of BLA backbones +* which can be learned in parallel +*/ +BATADV_ATTR_BLA_BACKBONE_MAX_LEARNED , + +/** +* @BATADV_ATTR_BLA_CLAIM_MAX_LEARNED: defines the maximum number of BLA claim +* which can be learned in parallel +*/ +BATADV_ATTR_BLA_CLAIM_MAX_LEARNED , +/* add attributes above here, update the policy in netlink.c */ /**
event.c +20 -0
@@ -205,10 +205,22 @@ static void event_parse_set_mesh(struct nlattr **attrs, const char *prefix)printf ("* bonding %s\n" ,u8_to_boolstr (attrs[BATADV_ATTR_BONDING_ENABLED ])); +if (attrs[BATADV_ATTR_BLA_BACKBONE_MAX_LEARNED ]) +printf ("* bla_backbone_max_learned %u\n" , +nla_get_u32 (attrs[BATADV_ATTR_BLA_BACKBONE_MAX_LEARNED ])); + +if (attrs[BATADV_ATTR_BLA_CLAIM_MAX_LEARNED ]) +printf ("* bla_claim_max_learned %u\n" , +nla_get_u32 (attrs[BATADV_ATTR_BLA_CLAIM_MAX_LEARNED ])); +if (attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED ])printf ("* bridge_loop_avoidance %s\n" ,u8_to_boolstr (attrs[BATADV_ATTR_BRIDGE_LOOP_AVOIDANCE_ENABLED ])); +if (attrs[BATADV_ATTR_DAT_MAX_LEARNED ]) +printf ("* dat_max_learned %u\n" , +nla_get_u32 (attrs[BATADV_ATTR_DAT_MAX_LEARNED ])); +if (attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED ])printf ("* distributed_arp_table %s\n" ,u8_to_boolstr (attrs[BATADV_ATTR_DISTRIBUTED_ARP_TABLE_ENABLED ]));
@@ -282,9 +294,17 @@ static void event_parse_set_mesh(struct nlattr **attrs, const char *prefix)printf ("* multicast_forceflood %s\n" ,u8_to_boolstr (attrs[BATADV_ATTR_MULTICAST_FORCEFLOOD_ENABLED ])); +if (attrs[BATADV_ATTR_NEIGH_MAX_LEARNED ]) +printf ("* neigh_max_learned %u\n" , +nla_get_u32 (attrs[BATADV_ATTR_NEIGH_MAX_LEARNED ])); +if (attrs[BATADV_ATTR_ORIG_INTERVAL ])printf ("* orig_interval %u ms\n" ,nla_get_u32 (attrs[BATADV_ATTR_ORIG_INTERVAL ])); + +if (attrs[BATADV_ATTR_ORIG_MAX_LEARNED ]) +printf ("* orig_max_learned %u\n" , +nla_get_u32 (attrs[BATADV_ATTR_ORIG_MAX_LEARNED ])); }static void event_parse_set_hardif (struct nlattr **attrs,const char *prefix)
genl_json.c +20 -0
@@ -461,6 +461,26 @@ static const struct nla_policy_json batadv_genl_json[NUM_BATADV_ATTR] = { .name = "multicast_fanout", .cb = nljson_print_uint32, }, + [BATADV_ATTR_NEIGH_MAX_LEARNED] = { + .name = "neigh_max_learned", + .cb = nljson_print_uint32, + }, + [BATADV_ATTR_ORIG_MAX_LEARNED] = { + .name = "orig_max_learned", + .cb = nljson_print_uint32, + }, + [BATADV_ATTR_DAT_MAX_LEARNED] = { + .name = "dat_max_learned", + .cb = nljson_print_uint32, + }, + [BATADV_ATTR_BLA_BACKBONE_MAX_LEARNED] = { + .name = "bla_backbone_max_learned", + .cb = nljson_print_uint32, + }, + [BATADV_ATTR_BLA_CLAIM_MAX_LEARNED] = { + .name = "bla_claim_max_learned", + .cb = nljson_print_uint32, + }, };void netlink_print_json_entries (struct nlattr *attrs[],struct json_opts *json_opts)
limit.c new file +176 -0
176 lines not on this page · raw message
man/batctl.8 +7 -0
@@ -321,6 +321,13 @@ Example 2: 0x00040000/0xffff0000 Example 3: 16 or 0x0F .br .TP +[\fBmeshif\fP \fInetdev\fP] \fBlimit\fP|\fBlt\fP [\fIlimit\fP \fIvalue\fP ...] +If no parameter is given the current limits for remote learned objects are displayed. Otherwise the parameters are +interpreted as pairs of limit name and value and are used to set the given limits. Limits which are not specified as +parameter are left unmodified. A limit of 0 disables the limit for this object type. Valid limit names are +\fBneighbors\fP, \fBoriginators\fP, \fBdat\fP, \fBbla_backbones\fP and +\fBbla_claims\fP. +.TP [\fBmeshif\fP \fInetdev\fP] \fBloglevel\fP|\fBll\fP [\fIlevel\fP ...] If no parameter is given the current log level settings are displayed otherwise the parameter(s) is/are used to set the log level. Level 'none' disables all verbose logging. Level 'batman' enables messages related to routing / flooding / broadcasting.
netlink.c +15 -0
@@ -227,6 +227,21 @@ struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = { [BATADV_ATTR_MULTICAST_FANOUT ] = { .type =NLA_U32 , }, + [BATADV_ATTR_NEIGH_MAX_LEARNED ] = { + .type =NLA_U32 , + }, + [BATADV_ATTR_ORIG_MAX_LEARNED ] = { + .type =NLA_U32 , + }, + [BATADV_ATTR_DAT_MAX_LEARNED ] = { + .type =NLA_U32 , + }, + [BATADV_ATTR_BLA_BACKBONE_MAX_LEARNED ] = { + .type =NLA_U32 , + }, + [BATADV_ATTR_BLA_CLAIM_MAX_LEARNED ] = { + .type =NLA_U32 , + }, };int netlink_create (struct state *state)
---
base-commit: 48c3e05b3d7f3a135e2d8c3460f0f4d0411cf58e
change-id: 20260712-limit-7698ea22f298
Best regards,
Signature · 1 line
Sven Eckelmann <[email protected]>