diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2023-04-07 16:21:57 -0600 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2023-04-24 22:48:42 +0200 |
commit | 375505a4a8068bf7cb623e18c3aedb831c17fd0e (patch) | |
tree | ef076f2fbef1eaca39c65eddcc0b9f5cd3a9b9cc /include | |
parent | 6231d3fa4af1e403555a6d4a139b3867218fab74 (diff) |
mnl: set SO_SNDBUF before SO_SNDBUFFORCE
Set SO_SNDBUF before SO_SNDBUFFORCE: Unpriviledged user namespace does
not have CAP_NET_ADMIN on the host (user_init_ns) namespace.
SO_SNDBUF always succeeds in Linux, always try SO_SNDBUFFORCE after it.
Moreover, suggest the user to bump socket limits if EMSGSIZE after
having see EPERM previously, when calling SO_SNDBUFFORCE.
Provide a hint to the user too:
# nft -f test.nft
netlink: Error: Could not process rule: Message too long
Please, rise /proc/sys/net/core/wmem_max on the host namespace. Hint: 4194304 bytes
Dave Pfike says:
Prior to this patch, nft inside a systemd-nspawn container was failing
to install my ruleset (which includes a large-ish map), with the error
netlink: Error: Could not process rule: Message too long
strace reveals:
setsockopt(3, SOL_SOCKET, SO_SNDBUFFORCE, [524288], 4) = -1 EPERM (Operation not permitted)
This is despite the nspawn process supposedly having CAP_NET_ADMIN.
A web search reveals at least one other user having the same issue:
http://old.reddit.com/r/Proxmox/comments/scnoav/lxc_container_debian_11_nftables_geoblocking/
Reported-by: Dave Pifke <dave@pifke.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/netlink.h | 1 | ||||
-rw-r--r-- | include/utils.h | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/include/netlink.h b/include/netlink.h index 0d97f71c..d52434c7 100644 --- a/include/netlink.h +++ b/include/netlink.h @@ -84,6 +84,7 @@ struct netlink_ctx { const void *data; uint32_t seqnum; struct nftnl_batch *batch; + int maybe_emsgsize; }; extern struct nftnl_expr *alloc_nft_expr(const char *name); diff --git a/include/utils.h b/include/utils.h index ffbe2cbb..d5073e06 100644 --- a/include/utils.h +++ b/include/utils.h @@ -136,5 +136,6 @@ extern void *xzalloc(size_t size); extern void *xzalloc_array(size_t nmemb, size_t size); extern char *xstrdup(const char *s); extern void xstrunescape(const char *in, char *out); +extern int round_pow_2(unsigned int value); #endif /* NFTABLES_UTILS_H */ |