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

     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  # TODO: due to autobind a socket can bind to port 0, that will result in a random port which is not reproducible
     5  
     6  include <stddef.h>
     7  include <sys/types.h>
     8  include <sys/socket.h>
     9  include <netinet/in.h>
    10  include <compat/linux/common/linux_socket.h>
    11  
    12  resource sock[fd]
    13  type sock_port proc[20000, 4, int16be]
    14  
    15  # TODO: describe socketcall syscall
    16  
    17  socket(domain flags[socket_domain], type flags[socket_type], proto int8) sock
    18  compat_30_socket(domain flags[socket_domain], type flags[socket_type], proto int8) sock
    19  socketpair(domain flags[socket_domain], type flags[socket_type], proto int8, fds ptr[out, sock_pair])
    20  bind(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    21  connect(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    22  accept(s sock, addr ptr[out, sockaddr_storage, opt], addrlen ptr[inout, len[addr, int32]]) sock
    23  compat_43_oaccept(s sock, name buffer[out], namelen ptr[inout, len[name, int32]]) sock
    24  paccept(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]], flags flags[accept_flags]) sock
    25  sendto(fd sock, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    26  recvfrom(fd sock, buf buffer[out], len len[buf], f flags[recv_flags], frm ptr[in, sockaddr_storage, opt], frmlen len[frm])
    27  compat_43_orecvfrom(s sock, buf buffer[out], len len[buf], f flags[recv_flags], frm buffer[in], frmlen len[frm])
    28  getsockname(fd sock, addr ptr[out, sockaddr_storage], addrlen ptr[inout, len[addr, int32]])
    29  compat_43_ogetsockname(fdec sock, asa buffer[out], alen ptr[inout, len[asa, int32]])
    30  getpeername(fd sock, peer ptr[out, sockaddr_storage], peerlen ptr[inout, len[peer, int32]])
    31  compat_43_ogetpeername(fdes sock, asa buffer[out], alen ptr[inout, len[asa, int32]])
    32  compat_43_osend(s sock, msg buffer[in], len len[msg], f flags[send_flags])
    33  compat_43_orecv(s sock, msg buffer[out], len len[msg], f flags[recv_flags])
    34  compat_43_osendmsg(s sock, msg buffer[in], f flags[send_flags])
    35  compat_43_orecvmsg(s sock, msg ptr[inout, recv_omsghdr], f flags[recv_flags])
    36  
    37  sendmsg(fd sock, msg ptr[in, send_msghdr], f flags[send_flags])
    38  sendmmsg(s sock, mmsg ptr[inout, send_mmsghdr], len len[mmsg], f flags[send_flags], timeout ptr[in, timespec, opt])
    39  recvmsg(fd sock, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    40  recvmmsg(s sock, mmsg ptr[inout, recv_mmsghdr], len len[mmsg], f flags[recv_flags], timeout ptr[in, timespec, opt])
    41  
    42  listen(fd sock, backlog int32)
    43  shutdown(fd sock, how flags[shutdown_flags])
    44  
    45  getsockopt(fd sock, level int32, optname int32, optval buffer[out], optlen ptr[inout, len[optval, int32]])
    46  setsockopt(fd sock, level int32, optname int32, optval buffer[in], optlen len[optval])
    47  
    48  socket_domain = PF_LOCAL, PF_INET, PF_INET6, PF_NS, PF_BLUETOOTH, PF_APPLETALK, PF_CAN
    49  socket_type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_NONBLOCK, SOCK_CLOEXEC, SOCK_NOSIGPIPE
    50  accept_flags = SOCK_NONBLOCK, SOCK_CLOEXEC, SOCK_NOSIGPIPE
    51  shutdown_flags = SHUT_RD, SHUT_WR, SHUT_RDWR
    52  send_flags = MSG_OOB, MSG_PEEK, MSG_DONTROUTE, MSG_EOR, MSG_NOSIGNAL
    53  recv_flags = MSG_OOB, MSG_PEEK, MSG_DONTROUTE, MSG_EOR, MSG_TRUNC, MSG_CTRUNC, MSG_WAITALL, MSG_DONTWAIT, MSG_BCAST, MSG_MCAST, MSG_NOSIGNAL, MSG_CMSG_CLOEXEC, MSG_NBIO, MSG_WAITFORONE, MSG_NOTIFICATION
    54  cmsg_levels = SOL_SOCKET, IPPROTO_ICMP, LINUX_SOL_IP, LINUX_SOL_TCP, LINUX_SOL_UDP, LINUX_SOL_IPV6, LINUX_SOL_IPX, LINUX_SOL_AX25
    55  addr_family = AF_UNSPEC, AF_LOCAL, AF_UNIX, AF_INET, AF_IMPLINK, AF_PUP, AF_CHAOS, AF_NS, AF_ISO, AF_OSI, AF_ECMA, AF_DATAKIT, AF_CCITT, AF_SNA, AF_DECnet, AF_DLI, AF_LAT, AF_HYLINK, AF_APPLETALK, AF_OROUTE, AF_LINK, AF_COIP, AF_CNT, pseudo_AF_RTIP, pseudo_AF_PIP, pseudo_AF_XTP, AF_IPX, AF_INET6, AF_ISDN, AF_E164, AF_NATM, AF_ARP, pseudo_AF_KEY, pseudo_AF_HDRCMPLT, AF_BLUETOOTH, AF_IEEE80211, AF_MPLS, AF_ROUTE, AF_CAN, AF_ETHER, AF_MAX
    56  
    57  sock_pair {
    58  	fd0	sock
    59  	fd1	sock
    60  }
    61  
    62  # This sockaddr type corresponds to the sockaddr_storage type and is 128 bytes size.
    63  sockaddr_storage [
    64  	len	int8
    65  	family	flags[addr_family, int8]
    66  	data	array[int8, 14]
    67  ]
    68  
    69  send_mmsghdr {
    70  	hdr	ptr[inout, send_msghdr]
    71  	len	int32
    72  }
    73  
    74  send_msghdr {
    75  	msg_name	ptr[in, sockaddr_storage, opt]
    76  	msg_namelen	len[msg_name, int32]
    77  	msg_iov		ptr[in, array[iovec_in]]
    78  	msg_iovlen	len[msg_iov, intptr]
    79  	msg_control	ptr[in, array[cmsghdr]]
    80  	msg_controllen	bytesize[msg_control, intptr]
    81  	msg_flags	const[0, int32]
    82  }
    83  
    84  recv_mmsghdr {
    85  	hdr	ptr[inout, recv_msghdr]
    86  	len	int32
    87  }
    88  
    89  recv_msghdr {
    90  	msg_name	ptr[out, sockaddr_storage, opt]
    91  	msg_namelen	len[msg_name, int32]
    92  	msg_iov		ptr[in, array[iovec_out]]
    93  	msg_iovlen	len[msg_iov, intptr]
    94  	msg_control	buffer[out]
    95  	msg_controllen	len[msg_control, intptr]
    96  	msg_flags	const[0, int32]
    97  }
    98  
    99  recv_omsghdr {
   100  	msg_name		ptr[out, sockaddr_storage, opt]
   101  	msg_namelen		len[msg_name, int32]
   102  	msg_iov			ptr[in, iovec_out]
   103  	msg_iovlen		len[msg_iov, int32]
   104  	msg_accrights		buffer[out]
   105  	msg_accrightslen	len[msg_accrights, int32]
   106  }
   107  
   108  cmsghdr {
   109  	cmsg_len	len[parent, intptr]
   110  	cmsg_level	flags[cmsg_levels, int32]
   111  	cmsg_type	int32
   112  	data		array[int8]
   113  } [align[PTR_SIZE]]
   114  
   115  # Socket options
   116  
   117  getsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[out, int32], optlen ptr[inout, len[optval, int32]])
   118  setsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[in, int32], optlen len[optval])
   119  getsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[out, linger], optlen ptr[inout, len[optval, int32]])
   120  setsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[in, linger], optlen len[optval])
   121  getsockopt$sock_cred(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[out, ucred], optlen ptr[inout, len[optval, int32]])
   122  setsockopt$sock_cred(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[in, ucred], optlen len[optval])
   123  getsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[out, timeval], optlen ptr[inout, len[optval, int32]])
   124  setsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[in, timeval], optlen len[optval])
   125  getsockopt$SO_PEERCRED(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[out, ucred], optlen len[optval])
   126  
   127  sockopt_opt_sock_int = SO_DEBUG, SO_REUSEADDR, SO_REUSEPORT, SO_KEEPALIVE, SO_DONTROUTE, SO_LINGER, SO_BROADCAST, SO_OOBINLINE, SO_SNDBUF, SO_RCVBUF, SO_SNDLOWAT, SO_RCVLOWAT, SO_TIMESTAMP, SO_ACCEPTFILTER, SO_NOSIGPIPE, SO_TYPE, SO_ERROR
   128  sockopt_opt_sock_timeval = SO_RCVTIMEO, SO_SNDTIMEO