github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/linux/socket_can.txt (about)

     1  # Copyright 2018 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  # AF_CAN support.
     5  
     6  include <linux/net.h>
     7  include <linux/socket.h>
     8  include <uapi/linux/if.h>
     9  include <uapi/linux/can.h>
    10  include <uapi/linux/can/raw.h>
    11  include <uapi/linux/can/bcm.h>
    12  include <uapi/linux/can/j1939.h>
    13  
    14  resource sock_can[sock]
    15  resource sock_can_raw[sock_can]
    16  resource sock_can_bcm[sock_can]
    17  resource sock_can_j1939[sock_can]
    18  resource ifindex_vcan[ifindex]
    19  
    20  socket$can_raw(domain const[AF_CAN], type const[SOCK_RAW], proto const[CAN_RAW]) sock_can_raw
    21  bind$can_raw(fd sock_can_raw, addr ptr[in, sockaddr_can], len bytesize[addr])
    22  sendmsg$can_raw(fd sock_can_raw, msg ptr[in, msghdr_can[can_raw_msg]], f flags[send_flags])
    23  recvmsg$can_raw(fd sock_can_raw, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    24  setsockopt$CAN_RAW_FILTER(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_FILTER], val ptr[in, array[can_filter]], len bytesize[val])
    25  setsockopt$CAN_RAW_ERR_FILTER(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_ERR_FILTER], val ptr[in, int32], len bytesize[val])
    26  setsockopt$CAN_RAW_LOOPBACK(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_LOOPBACK], val ptr[in, bool32], len bytesize[val])
    27  setsockopt$CAN_RAW_RECV_OWN_MSGS(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_RECV_OWN_MSGS], val ptr[in, bool32], len bytesize[val])
    28  setsockopt$CAN_RAW_FD_FRAMES(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_FD_FRAMES], val ptr[in, bool32], len bytesize[val])
    29  setsockopt$CAN_RAW_JOIN_FILTERS(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_JOIN_FILTERS], val ptr[in, bool32], len bytesize[val])
    30  getsockopt$CAN_RAW_FILTER(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_FILTER], val ptr[out, array[can_filter]], len ptr[inout, bytesize[val, int32]])
    31  getsockopt$CAN_RAW_LOOPBACK(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_LOOPBACK], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    32  getsockopt$CAN_RAW_RECV_OWN_MSGS(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_RECV_OWN_MSGS], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    33  getsockopt$CAN_RAW_FD_FRAMES(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_FD_FRAMES], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    34  getsockopt$CAN_RAW_JOIN_FILTERS(fd sock_can_raw, level const[SOL_CAN_RAW], opt const[CAN_RAW_JOIN_FILTERS], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    35  
    36  socket$can_bcm(domain const[AF_CAN], type const[SOCK_DGRAM], proto const[CAN_BCM]) sock_can_bcm
    37  connect$can_bcm(fd sock_can_bcm, addr ptr[in, sockaddr_can], len bytesize[addr])
    38  sendmsg$can_bcm(fd sock_can_bcm, msg ptr[in, msghdr_can[can_bcm_msg]], f flags[send_flags])
    39  recvmsg$can_bcm(fd sock_can_bcm, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    40  
    41  socket$can_j1939(domain const[AF_CAN], type const[SOCK_DGRAM], proto const[CAN_J1939]) sock_can_j1939
    42  bind$can_j1939(fd sock_can_j1939, addr ptr[in, sockaddr_can_j1939], len bytesize[addr])
    43  connect$can_j1939(fd sock_can_j1939, addr ptr[in, sockaddr_can_j1939], len bytesize[addr])
    44  sendmsg$can_j1939(fd sock_can_j1939, msg ptr[in, msghdr_can_j1939], f flags[send_flags])
    45  recvmsg$can_j1939(fd sock_can_j1939, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    46  setsockopt$SO_J1939_FILTER(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_FILTER], val ptr[in, array[j1939_filter]], len bytesize[val])
    47  setsockopt$SO_J1939_PROMISC(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_PROMISC], val ptr[in, bool32], len bytesize[val])
    48  setsockopt$SO_J1939_ERRQUEUE(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_ERRQUEUE], val ptr[in, bool32], len bytesize[val])
    49  setsockopt$SO_J1939_SEND_PRIO(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_SEND_PRIO], val ptr[in, int32[0:7]], len bytesize[val])
    50  getsockopt$SO_J1939_PROMISC(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_PROMISC], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    51  getsockopt$SO_J1939_ERRQUEUE(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_ERRQUEUE], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    52  getsockopt$SO_J1939_SEND_PRIO(fd sock_can_j1939, level const[SOL_CAN_J1939], opt const[SO_J1939_SEND_PRIO], val ptr[out, int32], len ptr[inout, bytesize[val, int32]])
    53  
    54  ioctl$ifreq_SIOCGIFINDEX_vcan(fd sock, cmd const[SIOCGIFINDEX], arg ptr[out, ifreq_dev_t[vcan_device_names, ifindex_vcan]])
    55  vcan_device_names = "vcan0", "vxcan0", "vxcan1"
    56  
    57  sockaddr_can {
    58  	can_family	const[AF_CAN, int16]
    59  	can_ifindex	ifindex_vcan[opt]
    60  	rx_id		const[0, int32]
    61  	tx_id		const[0, int32]
    62  }
    63  
    64  sockaddr_can_j1939 {
    65  	can_family	const[AF_CAN, int16]
    66  	can_ifindex	ifindex_vcan
    67  	name		can_j1939_name
    68  	pgn		can_j1939_pgn
    69  	addr		can_j1939_addr
    70  }
    71  
    72  can_j1939_pgn {
    73  	pgn_ps		flags[can_j1939_pgn_ps, int8]
    74  	pgn_pf		flags[can_j1939_pgn_pf, int8]
    75  	pgn_flags	flags[can_j1939_pgn_flags, int8]
    76  	pgn_unused	const[0, int8]
    77  } [align[4]]
    78  
    79  can_j1939_pgn_ps = 0, 1, 2
    80  can_j1939_pgn_pf = 0, 1, 0xf0, 0xff
    81  can_j1939_pgn_flags = 0, 1, 2, 3, 4
    82  type can_j1939_name int64[0:3]
    83  type can_j1939_addr flags[can_j1939_addrs, int8]
    84  can_j1939_addrs = J1939_MAX_UNICAST_ADDR, J1939_IDLE_ADDR, J1939_NO_ADDR, 0, 1, 2
    85  
    86  type msghdr_can[MSG] {
    87  	addr	ptr[in, sockaddr_can, opt]
    88  	addrlen	len[addr, int32]
    89  	vec	ptr[in, iovec[in, MSG]]
    90  	vlen	const[1, intptr]
    91  	ctrl	const[0, intptr]
    92  	ctrllen	const[0, intptr]
    93  	f	flags[send_flags, int32]
    94  }
    95  
    96  msghdr_can_j1939 {
    97  	addr	ptr[in, sockaddr_can_j1939, opt]
    98  	addrlen	len[addr, int32]
    99  	vec	ptr[in, iovec[in, array[int8]]]
   100  	vlen	const[1, intptr]
   101  	ctrl	const[0, intptr]
   102  	ctrllen	const[0, intptr]
   103  	f	flags[send_flags, int32]
   104  }
   105  
   106  can_raw_msg [
   107  	can	can_frame
   108  	canfd	canfd_frame
   109  ] [varlen]
   110  
   111  can_bcm_msg {
   112  	opcode	flags[can_bcm_opcodes, int32]
   113  	flags	flags[can_bcm_flags, int32]
   114  	count	int32
   115  	ival1	timeval
   116  	ival2	timeval
   117  	can_id	canid_t
   118  	nframes	const[1, int32]
   119  	frames	can_raw_msg
   120  }
   121  
   122  type can_frame_t[DATA_SIZE] {
   123  	can_id	canid_t
   124  	len	int8[0:DATA_SIZE]
   125  	flags	flags[can_frame_flags, int8]
   126  	__res0	const[0, int8]
   127  	__res1	const[0, int8]
   128  	data	array[int8, DATA_SIZE]
   129  }
   130  
   131  type can_frame can_frame_t[CAN_MAX_DLEN]
   132  type canfd_frame can_frame_t[CANFD_MAX_DLEN]
   133  
   134  canid_t {
   135  	id	int32:29[0:4]
   136  	err	int32:1
   137  	rtr	int32:1
   138  	eff	int32:1
   139  }
   140  
   141  can_filter {
   142  	can_id		canid_t
   143  	can_mask	canid_t
   144  }
   145  
   146  j1939_filter {
   147  	name		can_j1939_name
   148  	name_mask	can_j1939_name
   149  	pgn		can_j1939_pgn
   150  	pgn_mask	can_j1939_pgn
   151  	addr		can_j1939_addr
   152  	addr_mask	can_j1939_addr
   153  }
   154  
   155  can_bcm_opcodes = TX_SETUP, TX_DELETE, TX_READ, TX_SEND, RX_SETUP, RX_DELETE, RX_READ
   156  can_bcm_flags = SETTIMER, STARTTIMER, TX_COUNTEVT, TX_ANNOUNCE, TX_CP_CAN_ID, RX_FILTER_ID, RX_CHECK_DLC, RX_NO_AUTOTIMER, RX_ANNOUNCE_RESUME, TX_RESET_MULTI_IDX, RX_RTR_FRAME, CAN_FD_FRAME
   157  can_frame_flags = CANFD_BRS, CANFD_ESI