github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/openbsd/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 <sys/types.h>
     7  include <sys/socket.h>
     8  include <netinet/in.h>
     9  
    10  resource sock[fd]
    11  type sock_port proc[20000, 4, int16be]
    12  
    13  # TODO: describe socketcall syscall
    14  
    15  socket(domain flags[socket_domain], type flags[socket_type], proto int8) sock
    16  socketpair(domain flags[socket_domain], type flags[socket_type], proto int8, fds ptr[out, sock_pair])
    17  bind(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    18  connect(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    19  accept(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]]) sock
    20  # paccept(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]], flags flags[accept_flags]) sock
    21  sendto(fd sock, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    22  recvfrom(fd sock, buf buffer[out], len len[buf], f flags[recv_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    23  getsockname(fd sock, addr ptr[out, sockaddr_storage], addrlen ptr[inout, len[addr, int32]])
    24  getpeername(fd sock, peer ptr[out, sockaddr_storage], peerlen ptr[inout, len[peer, int32]])
    25  
    26  sendmsg(fd sock, msg ptr[in, send_msghdr], f flags[send_flags])
    27  sendmmsg(fd sock, mmsg ptr[inout, send_mmsghdr], len len[mmsg], f flags[send_flags])
    28  recvmsg(fd sock, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    29  recvmmsg(fd sock, mmsg ptr[inout, recv_mmsghdr], len len[mmsg], f flags[recv_flags], timeout ptr[in, timespec, opt])
    30  
    31  listen(fd sock, backlog int32)
    32  shutdown(fd sock, how flags[shutdown_flags])
    33  
    34  getsockopt(fd sock, level int32, optname int32, optval buffer[out], optlen ptr[inout, len[optval, int32]])
    35  setsockopt(fd sock, level int32, optname int32, optval buffer[in], optlen len[optval])
    36  
    37  socket_domain = AF_LOCAL, AF_INET, AF_INET6, AF_NS, AF_BLUETOOTH, AF_APPLETALK
    38  socket_type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_NONBLOCK, SOCK_CLOEXEC
    39  # accept_flags = SOCK_NONBLOCK, SOCK_CLOEXEC
    40  shutdown_flags = SHUT_RD, SHUT_WR, SHUT_RDWR
    41  send_flags = MSG_OOB, MSG_PEEK, MSG_DONTROUTE, MSG_EOR, MSG_NOSIGNAL
    42  recv_flags = MSG_CMSG_CLOEXEC, MSG_OOB, MSG_PEEK, MSG_WAITALL, MSG_WAITFORONE
    43  cmsg_levels = SOL_SOCKET, IPPROTO_ICMP
    44  
    45  sock_pair {
    46  	fd0	sock
    47  	fd1	sock
    48  }
    49  
    50  # This sockaddr type corresponds to the sockaddr_storage type and is 128 bytes size.
    51  sockaddr_storage [
    52  	un	sockaddr_un
    53  	in	sockaddr_in
    54  	in6	sockaddr_in6
    55  ] [varlen]
    56  
    57  send_msghdr {
    58  	msg_name	ptr[in, sockaddr_storage, opt]
    59  	msg_namelen	len[msg_name, int32]
    60  	msg_iov		ptr[in, array[iovec_in]]
    61  	msg_iovlen	len[msg_iov, intptr]
    62  	msg_control	ptr[in, array[cmsghdr]]
    63  	msg_controllen	bytesize[msg_control, intptr]
    64  	msg_flags	const[0, int32]
    65  }
    66  
    67  send_mmsghdr {
    68  	hdr	ptr[inout, send_msghdr]
    69  	len	int32
    70  }
    71  
    72  recv_msghdr {
    73  	msg_name	ptr[out, sockaddr_storage, opt]
    74  	msg_namelen	len[msg_name, int32]
    75  	msg_iov		ptr[in, array[iovec_out]]
    76  	msg_iovlen	len[msg_iov, intptr]
    77  	msg_control	buffer[out]
    78  	msg_controllen	len[msg_control, intptr]
    79  	msg_flags	const[0, int32]
    80  }
    81  
    82  recv_mmsghdr {
    83  	hdr	ptr[inout, recv_msghdr]
    84  	len	int32
    85  }
    86  
    87  cmsghdr {
    88  	cmsg_len	len[parent, intptr]
    89  	cmsg_level	flags[cmsg_levels, int32]
    90  	cmsg_type	int32
    91  	data		array[int8]
    92  } [align[PTR_SIZE]]
    93  
    94  # Socket options
    95  
    96  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]])
    97  setsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[in, int32], optlen len[optval])
    98  getsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[out, linger], optlen ptr[inout, len[optval, int32]])
    99  setsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[in, linger], optlen len[optval])
   100  getsockopt$sock_cred(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[out, ucred], optlen ptr[inout, len[optval, int32]])
   101  setsockopt$sock_cred(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[in, ucred], optlen len[optval])
   102  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]])
   103  setsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[in, timeval], optlen len[optval])
   104  getsockopt$SO_PEERCRED(fd sock, level const[SOL_SOCKET], optname const[SO_PEERCRED], optval ptr[out, ucred], optlen len[optval])
   105  
   106  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_TYPE, SO_ERROR
   107  sockopt_opt_sock_timeval = SO_RCVTIMEO, SO_SNDTIMEO