kernel_optimize_test/net/ipv4
Andrey Ignatov 1cedee13d2 bpf: Hooks for sys_sendmsg
In addition to already existing BPF hooks for sys_bind and sys_connect,
the patch provides new hooks for sys_sendmsg.

It leverages existing BPF program type `BPF_PROG_TYPE_CGROUP_SOCK_ADDR`
that provides access to socket itlself (properties like family, type,
protocol) and user-passed `struct sockaddr *` so that BPF program can
override destination IP and port for system calls such as sendto(2) or
sendmsg(2) and/or assign source IP to the socket.

The hooks are implemented as two new attach types:
`BPF_CGROUP_UDP4_SENDMSG` and `BPF_CGROUP_UDP6_SENDMSG` for UDPv4 and
UDPv6 correspondingly.

UDPv4 and UDPv6 separate attach types for same reason as sys_bind and
sys_connect hooks, i.e. to prevent reading from / writing to e.g.
user_ip6 fields when user passes sockaddr_in since it'd be out-of-bound.

The difference with already existing hooks is sys_sendmsg are
implemented only for unconnected UDP.

For TCP it doesn't make sense to change user-provided `struct sockaddr *`
at sendto(2)/sendmsg(2) time since socket either was already connected
and has source/destination set or wasn't connected and call to
sendto(2)/sendmsg(2) would lead to ENOTCONN anyway.

Connected UDP is already handled by sys_connect hooks that can override
source/destination at connect time and use fast-path later, i.e. these
hooks don't affect UDP fast-path.

Rewriting source IP is implemented differently than that in sys_connect
hooks. When sys_sendmsg is used with unconnected UDP it doesn't work to
just bind socket to desired local IP address since source IP can be set
on per-packet basis by using ancillary data (cmsg(3)). So no matter if
socket is bound or not, source IP has to be rewritten on every call to
sys_sendmsg.

To do so two new fields are added to UAPI `struct bpf_sock_addr`;
* `msg_src_ip4` to set source IPv4 for UDPv4;
* `msg_src_ip6` to set source IPv6 for UDPv6.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-05-28 17:41:02 +02:00
..
bpfilter net: add skeleton of bpfilter kernel module 2018-05-23 13:23:40 -04:00
netfilter Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next 2018-05-23 16:37:11 -04:00
af_inet.c tcp: add TCP_ZEROCOPY_RECEIVE support for zerocopy receive 2018-04-29 21:29:55 -04:00
ah4.c
arp.c arp: fix arp_filter on l3slave devices 2018-04-05 22:05:03 -04:00
cipso_ipv4.c
datagram.c
devinet.c
esp4_offload.c
esp4.c
fib_frontend.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-26 19:46:15 -04:00
fib_lookup.h
fib_notifier.c
fib_rules.c net: fib_rules: add extack support 2018-04-23 10:21:24 -04:00
fib_semantics.c net: Move fib_convert_metrics to metrics file 2018-04-17 23:41:15 -04:00
fib_trie.c net/ipv4: Udate fib_table_lookup tracepoint 2018-05-24 23:00:31 -04:00
fou.c
gre_demux.c
gre_offload.c
icmp.c
igmp.c
inet_connection_sock.c net: ipv4: remove define INET_CSK_DEBUG and unnecessary EXPORT_SYMBOL 2018-05-10 17:43:55 -04:00
inet_diag.c
inet_fragment.c inet: frags: remove inet_frag_maybe_warn_overflow() 2018-03-31 23:25:39 -04:00
inet_hashtables.c
inet_timewait_sock.c soreuseport: initialise timewait reuseport field 2018-04-07 22:32:32 -04:00
inetpeer.c inetpeer: fix uninit-value in inet_getpeer 2018-04-09 10:57:35 -04:00
ip_forward.c
ip_fragment.c inet: frags: fix ip6frag_low_thresh boundary 2018-04-04 12:04:59 -04:00
ip_gre.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
ip_input.c
ip_options.c
ip_output.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
ip_sockglue.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-26 19:46:15 -04:00
ip_tunnel_core.c net/ipv4: Update ip_tunnel_metadata_cnt static key to modern api 2018-05-10 15:13:33 -04:00
ip_tunnel.c ip_tunnel: better validate user provided tunnel names 2018-04-05 15:16:15 -04:00
ip_vti.c
ipcomp.c
ipconfig.c net: ipv4: ipconfig: fix unused variable 2018-05-13 20:27:25 -04:00
ipip.c
ipmr_base.c ipmr: properly check rhltable_init() return value 2018-05-22 15:31:15 -04:00
ipmr.c net: fib_rules: add extack support 2018-04-23 10:21:24 -04:00
Kconfig
Makefile ipv4: support sport, dport and ip_proto in RTM_GETROUTE 2018-05-23 15:14:12 -04:00
metrics.c net: Move fib_convert_metrics to metrics file 2018-04-17 23:41:15 -04:00
netfilter.c
netlink.c ipv4: support sport, dport and ip_proto in RTM_GETROUTE 2018-05-23 15:14:12 -04:00
ping.c ipv4: fix memory leaks in udp_sendmsg, ping_v4_sendmsg 2018-05-11 12:00:58 -04:00
proc.c tcp: add TCPAckCompressed SNMP counter 2018-05-18 11:40:27 -04:00
protocol.c
raw_diag.c
raw.c
route.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2018-05-24 22:20:51 -04:00
syncookies.c
sysctl_net_ipv4.c tcp: add tcp_comp_sack_nr sysctl 2018-05-18 11:40:27 -04:00
tcp_bbr.c tcp_bbr: fix to zero idle_restart only upon S/ACKed data 2018-05-02 11:12:32 -04:00
tcp_bic.c
tcp_cdg.c
tcp_cong.c
tcp_cubic.c
tcp_dctcp.c
tcp_diag.c
tcp_fastopen.c
tcp_highspeed.c
tcp_htcp.c
tcp_hybla.c
tcp_illinois.c
tcp_input.c tcp: do not aggressively quick ack after ECN events 2018-05-22 15:43:15 -04:00
tcp_ipv4.c tcp: add tcp_comp_sack_nr sysctl 2018-05-18 11:40:27 -04:00
tcp_lp.c
tcp_metrics.c
tcp_minisocks.c tcp: Add mark for TIMEWAIT sockets 2018-05-10 17:44:52 -04:00
tcp_nv.c
tcp_offload.c
tcp_output.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2018-05-21 16:01:54 -04:00
tcp_rate.c
tcp_recovery.c tcp: tcp_rack_reo_wnd() can be static 2018-05-18 13:28:40 -04:00
tcp_scalable.c
tcp_timer.c tcp: add SACK compression 2018-05-18 11:40:27 -04:00
tcp_ulp.c
tcp_vegas.c
tcp_vegas.h
tcp_veno.c
tcp_westwood.c
tcp_yeah.c
tcp.c tcp: add SACK compression 2018-05-18 11:40:27 -04:00
tunnel4.c
udp_diag.c
udp_impl.h
udp_offload.c udp: avoid refcount_t saturation in __udp_gso_segment() 2018-05-11 12:29:42 -04:00
udp_tunnel.c
udp.c bpf: Hooks for sys_sendmsg 2018-05-28 17:41:02 +02:00
udplite.c
xfrm4_input.c
xfrm4_mode_beet.c
xfrm4_mode_transport.c
xfrm4_mode_tunnel.c
xfrm4_output.c
xfrm4_policy.c
xfrm4_protocol.c
xfrm4_state.c
xfrm4_tunnel.c