From: planck kernel size experiment Subject: ipv4: reject optional header extensions The fixed-purpose logger exchanges ordinary unicast IPv4 packets with a 20-byte header. It neither configures socket-level IP_OPTIONS nor needs to accept source routes, record-route, timestamps, router alerts, or CIPSO. Replace the general option parser and rewriter with a narrow policy: empty options remain valid, attempts to configure options fail with EOPNOTSUPP, and option-bearing input fails validation. The no-op output helpers are therefore reachable only for the supported empty case. Measured effect on RV32: Image shrank by 8,192 bytes (1,216,696 to 1,208,504 bytes), with the TCP/UDP/Minix acceptance proof still passing. --- a/net/ipv4/Makefile +++ b/net/ipv4/Makefile @@ -4,7 +4,7 @@ # obj-y := route.o inetpeer.o protocol.o \ - ip_input.o ip_fragment.o ip_forward.o ip_options.o \ + ip_input.o ip_fragment.o ip_forward.o planck_no_options.o \ ip_output.o ip_sockglue.o inet_hashtables.o \ inet_timewait_sock.o inet_connection_sock.o \ tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \ --- /dev/null +++ b/net/ipv4/planck_no_options.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Deliberately support only the ordinary 20-byte IPv4 header. */ + +#include +#include +#include +#include + +void ip_options_build(struct sk_buff *skb, struct ip_options *opt, + __be32 daddr, struct rtable *rt) +{ +} + +int __ip_options_echo(struct net *net, struct ip_options *dopt, + struct sk_buff *skb, const struct ip_options *sopt) +{ + memset(dopt, 0, sizeof(*dopt)); + return sopt->optlen ? -EINVAL : 0; +} + +void ip_options_fragment(struct sk_buff *skb) +{ +} + +int __ip_options_compile(struct net *net, struct ip_options *opt, + struct sk_buff *skb, __be32 *info) +{ + if (info) + *info = 0; + return opt->optlen ? -EINVAL : 0; +} + +int ip_options_compile(struct net *net, struct ip_options *opt, + struct sk_buff *skb) +{ + return opt->optlen ? -EINVAL : 0; +} + +int ip_options_get(struct net *net, struct ip_options_rcu **optp, + sockptr_t data, int optlen) +{ + if (optlen) + return -EOPNOTSUPP; + kfree(*optp); + *optp = NULL; + return 0; +} + +void ip_options_undo(struct ip_options *opt) +{ +} + +void ip_forward_options(struct sk_buff *skb) +{ +} + +int ip_options_rcv_srr(struct sk_buff *skb, struct net_device *dev) +{ + return -EINVAL; +}