# Copyright 2017 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

# AF_IPX support.

include <linux/socket.h>
include <linux/net.h>
include <linux/if_ether.h>
include <linux/if_arp.h>
include <linux/ipx.h>

resource sock_ipx[sock]

socket$ipx(domain const[AF_IPX], type const[SOCK_DGRAM], proto const[0]) sock_ipx
socketpair$ipx(domain const[AF_IPX], type const[SOCK_DGRAM], proto const[0], fds ptr[out, ipx_pair])
bind$ipx(fd sock_ipx, addr ptr[in, sockaddr_ipx], addrlen len[addr])
connect$ipx(fd sock_ipx, addr ptr[in, sockaddr_ipx], addrlen len[addr])
accept$ipx(fd sock_ipx, peer ptr[out, sockaddr_ipx, opt], peerlen ptr[inout, len[peer, int32]]) sock_ipx
accept4$ipx(fd sock_ipx, peer ptr[out, sockaddr_ipx, opt], peerlen ptr[inout, len[peer, int32]], flags flags[accept_flags]) sock_ipx

sendto$ipx(fd sock_ipx, buf buffer[in], len len[buf], f flags[send_flags], addr ptr[in, sockaddr_ipx, opt], addrlen len[addr])
recvfrom$ipx(fd sock_ipx, buf buffer[out], len len[buf], f flags[recv_flags], addr ptr[in, sockaddr_ipx, opt], addrlen len[addr])
getsockname$ipx(fd sock_ipx, addr ptr[out, sockaddr_ipx], addrlen ptr[inout, len[addr, int32]])
getpeername$ipx(fd sock_ipx, peer ptr[out, sockaddr_ipx], peerlen ptr[inout, len[peer, int32]])

ipx_pair {
	fd0	sock_ipx
	fd1	sock_ipx
}

sockaddr_ipx {
	sipx_family	const[AF_IPX, int16]
	sipx_port	int16be
	sipx_network	int32be
	sipx_node	array[int8, 6]
	sipx_type	int8
	pad		const[0, int8]
}

# Specific options

getsockopt$ipx_IPX_TYPE(fd sock_ipx, level const[SOL_IPX], optname const[IPX_TYPE], optval ptr[out, int32], optlen ptr[inout, len[optval, int32]])
setsockopt$ipx_IPX_TYPE(fd sock_ipx, level const[SOL_IPX], optname const[IPX_TYPE], optval ptr[in, int32], optlen len[optval])

# ioctls

# TODO: SIOCDELRT & SIOCADDRT (net/ipx/ipx_route.c)

ioctl$sock_ipx_SIOCSIFADDR(fd sock_ipx, cmd const[SIOCSIFADDR], arg ptr[in, ifreq_t[sockaddr_ipx]])
ioctl$sock_ipx_SIOCGIFADDR(fd sock_ipx, cmd const[SIOCGIFADDR], arg ptr[inout, ifreq_t[sockaddr_ipx]])
ioctl$sock_ipx_SIOCAIPXITFCRT(fd sock_ipx, cmd const[SIOCAIPXITFCRT], arg ptr[in, int32])
ioctl$sock_ipx_SIOCAIPXPRISLT(fd sock_ipx, cmd const[SIOCAIPXPRISLT], arg ptr[in, int32])
ioctl$sock_ipx_SIOCIPXCFGDATA(fd sock_ipx, cmd const[SIOCIPXCFGDATA], arg ptr[out, ipx_config_data])
ioctl$sock_ipx_SIOCIPXNCPCONN(fd sock_ipx, cmd const[SIOCIPXNCPCONN], arg ptr[in, int16])

ipx_config_data {
	ipxcfg_auto_select_primary	int16
	ipxcfg_auto_create_interfaces	int16
}