1# Copyright 2017 syzkaller project authors. All rights reserved.
2# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3
4# http://man7.org/linux/man-pages/man7/packet.7.html
5# https://www.kernel.org/doc/Documentation/networking/packet_mmap.txt
6
7# AF_PACKET support.
8
9include <linux/socket.h>
10include <linux/net.h>
11include <linux/if_ether.h>
12include <linux/if_arp.h>
13
14define ETH_P_ALL_BE	htons(ETH_P_ALL)
15
16resource sock_packet[sock]
17
18socket$packet(domain const[AF_PACKET], type flags[packet_socket_type], proto const[ETH_P_ALL_BE]) sock_packet
19socketpair$packet(domain const[AF_PACKET], type flags[packet_socket_type], proto const[ETH_P_ALL_BE], fds ptr[out, packet_pair])
20bind$packet(fd sock_packet, addr ptr[in, sockaddr_ll], addrlen len[addr])
21connect$packet(fd sock_packet, addr ptr[in, sockaddr_ll], addrlen len[addr])
22accept$packet(fd sock_packet, peer ptr[out, sockaddr_ll, opt], peerlen ptr[inout, len[peer, int32]]) sock_packet
23accept4$packet(fd sock_packet, peer ptr[out, sockaddr_ll, opt], peerlen ptr[inout, len[peer, int32]], flags flags[accept_flags]) sock_packet
24
25sendto$packet(fd sock_packet, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_ll, opt], addrlen len[addr])
26recvfrom$packet(fd sock_packet, buf buffer[out], len len[buf], f flags[recv_flags], addr ptr[in, sockaddr_ll, opt], addrlen len[addr])
27getsockname$packet(fd sock_packet, addr ptr[out, sockaddr_ll], addrlen ptr[inout, len[addr, int32]])
28getpeername$packet(fd sock_packet, peer ptr[out, sockaddr_ll], peerlen ptr[inout, len[peer, int32]])
29
30packet_socket_type = SOCK_RAW, SOCK_DGRAM
31packet_protocols = ETH_P_802_3, ETH_P_AX25, ETH_P_ALL, ETH_P_802_2, ETH_P_SNAP, ETH_P_DDCMP, ETH_P_WAN_PPP, ETH_P_PPP_MP, ETH_P_LOCALTALK, ETH_P_CAN, ETH_P_CANFD, ETH_P_PPPTALK, ETH_P_TR_802_2, ETH_P_MOBITEX, ETH_P_CONTROL, ETH_P_IRDA, ETH_P_ECONET, ETH_P_HDLC, ETH_P_ARCNET, ETH_P_DSA, ETH_P_TRAILER, ETH_P_PHONET, ETH_P_IEEE802154, ETH_P_CAIF, ETH_P_XDSA
32
33packet_pair {
34	fd0	sock_packet
35	fd1	sock_packet
36}
37
38sockaddr_ll {
39	sll_family	const[AF_PACKET, int16]
40	sll_protocol	flags[packet_protocols, int16be]
41	sll_ifindex	ifindex
42	sll_hatype	const[ARPHRD_ETHER, int16]
43	sll_pkttype	int8
44	sll_halen	const[6, int8]
45	sll_addr	mac_addr
46	pad		array[const[0, int8], 2]
47}
48
49# Generic options
50
51packet_option_types_int = PACKET_RECV_OUTPUT, PACKET_COPY_THRESH, PACKET_AUXDATA, PACKET_ORIGDEV, PACKET_VERSION, PACKET_HDRLEN, PACKET_RESERVE, PACKET_LOSS, PACKET_VNET_HDR, PACKET_TX_TIMESTAMP, PACKET_TIMESTAMP, PACKET_FANOUT, PACKET_TX_HAS_OFF, PACKET_QDISC_BYPASS
52
53packet_option_types_buf = PACKET_ADD_MEMBERSHIP, PACKET_DROP_MEMBERSHIP, PACKET_RX_RING, PACKET_STATISTICS, PACKET_TX_RING, PACKET_FANOUT_DATA
54
55getsockopt$packet_int(fd sock_packet, level const[SOL_PACKET], optname flags[packet_option_types_int], optval ptr[out, int32], optlen ptr[inout, len[optval, int32]])
56setsockopt$packet_int(fd sock_packet, level const[SOL_PACKET], optname flags[packet_option_types_int], optval ptr[in, int32], optlen len[optval])
57getsockopt$packet_buf(fd sock_packet, level const[SOL_PACKET], optname flags[packet_option_types_buf], optval buffer[out], optlen ptr[inout, len[optval, int32]])
58setsockopt$packet_buf(fd sock_packet, level const[SOL_PACKET], optname flags[packet_option_types_buf], optval buffer[in], optlen len[optval])
59
60# Specific options
61
62packet_mreq {
63	mr_ifindex	ifindex
64	mr_type		const[ARPHRD_ETHER, int16]
65	mr_alen		len[mr_address, int16]
66	mr_address	mac_addr
67	pad		array[const[0, int8], 2]
68}
69
70setsockopt$packet_add_memb(fd sock_packet, level const[SOL_PACKET], optname const[PACKET_ADD_MEMBERSHIP], optval ptr[in, packet_mreq], optlen len[optval])
71setsockopt$packet_drop_memb(fd sock_packet, level const[SOL_PACKET], optname const[PACKET_DROP_MEMBERSHIP], optval ptr[in, packet_mreq], optlen len[optval])
72
73tpacket_req {
74	tp_block_size	int32
75	tp_block_nr	int32
76	tp_frame_size	int32
77	tp_frame_nr	int32
78}
79
80tpacket_req3 {
81	tp_block_size		int32
82	tp_block_nr		int32
83	tp_frame_size		int32
84	tp_frame_nr		int32
85	tp_retire_blk_tov	int32
86	tp_sizeof_priv		int32
87	tp_feature_req_word	int32
88}
89
90tpacket_req_u [
91	req	tpacket_req
92	req3	tpacket_req3
93] [varlen]
94
95setsockopt$packet_rx_ring(fd sock_packet, level const[SOL_PACKET], optname const[PACKET_RX_RING], optval ptr[in, tpacket_req_u], optlen len[optval])
96setsockopt$packet_tx_ring(fd sock_packet, level const[SOL_PACKET], optname const[PACKET_TX_RING], optval ptr[in, tpacket_req_u], optlen len[optval])
97
98packet_fanout_types = PACKET_FANOUT_HASH, PACKET_FANOUT_LB, PACKET_FANOUT_CPU, PACKET_FANOUT_ROLLOVER, PACKET_FANOUT_RND, PACKET_FANOUT_QM, PACKET_FANOUT_CBPF, PACKET_FANOUT_EBPF
99packet_fanout_flags = PACKET_FANOUT_FLAG_ROLLOVER, PACKET_FANOUT_FLAG_DEFRAG, PACKET_FANOUT_FLAG_UNIQUEID
100
101packet_fanout_val {
102	id	int16
103	type	flags[packet_fanout_types, int8]
104	flags	flags[packet_fanout_flags, int8]
105}
106
107setsockopt$packet_fanout(fd sock_packet, level const[SOL_PACKET], optname const[PACKET_FANOUT], optval ptr[in, packet_fanout_val], optlen len[optval])
108
109setsockopt$packet_fanout_data(fd sock_packet, level const[SOL_PACKET], optname const[PACKET_FANOUT_DATA], optval ptr[in, sock_fprog], optlen len[optval])
110