github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/sys/freebsd/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 <sys/sockio.h>
     9  include <netinet/in.h>
    10  
    11  resource sock[fd]
    12  type sock_port proc[20000, 4, int16be]
    13  
    14  # TODO: describe socketcall syscall
    15  
    16  socket(domain flags[socket_domain], type flags[socket_type], proto int8) sock
    17  socketpair(domain flags[socket_domain], type flags[socket_type], proto int8, fds ptr[out, sock_pair])
    18  bind(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    19  bindat(dirfd fd, fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    20  connect(fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    21  connectat(dirfd fd, fd sock, addr ptr[in, sockaddr_storage], addrlen len[addr])
    22  accept(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]]) sock
    23  accept4(fd sock, peer ptr[out, sockaddr_storage, opt], peerlen ptr[inout, len[peer, int32]], flags flags[accept_flags]) sock
    24  sendto(fd sock, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    25  recvfrom(fd sock, buf buffer[out], len len[buf], f flags[recv_flags], addr ptr[in, sockaddr_storage, opt], addrlen len[addr])
    26  getsockname(fd sock, addr ptr[out, sockaddr_storage], addrlen ptr[inout, len[addr, int32]])
    27  getpeername(fd sock, peer ptr[out, sockaddr_storage], peerlen ptr[inout, len[peer, int32]])
    28  
    29  sendmsg(fd sock, msg ptr[in, send_msghdr], f flags[send_flags])
    30  recvmsg(fd sock, msg ptr[inout, recv_msghdr], f flags[recv_flags])
    31  
    32  listen(fd sock, backlog int32)
    33  shutdown(fd sock, how flags[shutdown_flags])
    34  
    35  getsockopt(fd sock, level int32, optname int32, optval buffer[out], optlen ptr[inout, len[optval, int32]])
    36  setsockopt(fd sock, level int32, optname int32, optval buffer[in], optlen len[optval])
    37  
    38  socket_domain = AF_UNIX, AF_INET, AF_APPLETALK, AF_IPX, AF_INET6
    39  socket_type = SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_NONBLOCK, SOCK_CLOEXEC
    40  accept_flags = SOCK_NONBLOCK, SOCK_CLOEXEC
    41  shutdown_flags = SHUT_RD, SHUT_WR
    42  send_flags = MSG_OOB, MSG_DONTROUTE, MSG_EOR, MSG_DONTWAIT, MSG_EOF, MSG_NOSIGNAL
    43  recv_flags = MSG_OOB, MSG_PEEK, MSG_WAITALL, MSG_DONTWAIT, MSG_CMSG_CLOEXEC
    44  
    45  cmsg_levels = SOL_SOCKET, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_SCTP, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_UDPLITE
    46  
    47  sock_pair {
    48  	fd0	sock
    49  	fd1	sock
    50  }
    51  
    52  # This sockaddr type corresponds to the sockaddr_storage type and is 128 bytes size.
    53  sockaddr_storage [
    54  	un	sockaddr_un
    55  	in	sockaddr_in
    56  	in6	sockaddr_in6
    57  ] [varlen]
    58  
    59  send_msghdr {
    60  	msg_name	ptr[in, sockaddr_storage, opt]
    61  	msg_namelen	len[msg_name, int32]
    62  	msg_iov		ptr[in, array[iovec_in]]
    63  	msg_iovlen	len[msg_iov, intptr]
    64  	msg_control	ptr[in, array[cmsghdr]]
    65  	msg_controllen	bytesize[msg_control, intptr]
    66  	msg_flags	const[0, int32]
    67  }
    68  
    69  recv_msghdr {
    70  	msg_name	ptr[out, sockaddr_storage, opt]
    71  	msg_namelen	len[msg_name, int32]
    72  	msg_iov		ptr[in, array[iovec_out]]
    73  	msg_iovlen	len[msg_iov, intptr]
    74  	msg_control	buffer[out]
    75  	msg_controllen	len[msg_control, intptr]
    76  	msg_flags	const[0, int32]
    77  }
    78  
    79  cmsghdr {
    80  	cmsg_len	len[parent, intptr]
    81  	cmsg_level	flags[cmsg_levels, int32]
    82  	cmsg_type	int32
    83  	data		array[int8]
    84  } [align[PTR_SIZE]]
    85  
    86  accept_filter {
    87  	af_name	string[accept_filter_names, 16]
    88  	af_arg	array[int8, 240]
    89  }
    90  
    91  accept_filter_names = "accf_data", "accf_dns", "accf_http"
    92  
    93  # Socket options
    94  
    95  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]])
    96  setsockopt$sock_int(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_int], optval ptr[in, int32], optlen len[optval])
    97  getsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[out, linger], optlen ptr[inout, len[optval, int32]])
    98  setsockopt$sock_linger(fd sock, level const[SOL_SOCKET], optname const[SO_LINGER], optval ptr[in, linger], optlen len[optval])
    99  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]])
   100  setsockopt$sock_timeval(fd sock, level const[SOL_SOCKET], optname flags[sockopt_opt_sock_timeval], optval ptr[in, timeval], optlen len[optval])
   101  getsockopt$sock_accept_filter(fd sock, level const[SOL_SOCKET], optname const[SO_ACCEPTFILTER], optval ptr[out, accept_filter], optlen ptr[inout, len[optval, int32]])
   102  setsockopt$sock_accept_filter(fd sock, level const[SOL_SOCKET], optname const[SO_ACCEPTFILTER], optval ptr[in, accept_filter], optlen len[optval])
   103  sockopt_opt_sock_int = SO_DEBUG, SO_ACCEPTCONN, SO_REUSEADDR, SO_KEEPALIVE, SO_DONTROUTE, SO_BROADCAST, SO_USELOOPBACK, SO_OOBINLINE, SO_REUSEPORT, SO_TIMESTAMP, SO_NOSIGPIPE, SO_BINTIME, SO_NO_OFFLOAD, SO_NO_DDP, SO_REUSEPORT_LB, SO_SNDBUF, SO_RCVBUF, SO_SNDLOWAT, SO_RCVLOWAT, SO_ERROR, SO_TYPE, SO_LISTENQLIMIT, SO_LISTENQLEN, SO_LISTENINCQLEN, SO_SETFIB, SO_USER_COOKIE, SO_PROTOCOL, SO_PROTOTYPE, SO_TS_CLOCK, SO_MAX_PACING_RATE, SO_DOMAIN, SO_RERROR
   104  sockopt_opt_sock_timeval = SO_RCVTIMEO, SO_SNDTIMEO