8000 minix/minix/net/lwip/udpsock.c at master · gspu/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
997 lines (801 loc) · 26.5 KB

udpsock.c

File metadata and controls

997 lines (801 loc) · 26.5 KB
break;
case IPPROTO_IPV6:
if (!udpsock_is_ipv6(udp))
break;
switch (name) {
case IPV6_MULTICAST_IF:
ifindex = udp_get_multicast_netif_index(udp->udp_pcb);
val = (int)ifindex;
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
case IPV6_MULTICAST_LOOP:
flags = udp_flags(udp->udp_pcb);
val = !!(flags & UDP_FLAGS_MULTICAST_LOOP);
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
case IPV6_MULTICAST_HOPS:
val = udp_get_multicast_ttl(udp->udp_pcb);
return sockdriver_copyout_opt(data, &val, sizeof(val),
len);
}
break;
}
/* Handle all other options at the packet or IP level. */
udpsock_get_ipopts(udp, &ipopts);
return pktsock_getsockopt(&udp->udp_pktsock, level, name, data, len,
&ipopts);
}
/*
* Retrieve the local socket address of a UDP socket.
*/
static int
udpsock_getsockname(struct sock * sock, struct sockaddr * addr,
socklen_t * addr_len)
{
struct udpsock *udp = (struct udpsock *)sock;
ipsock_put_addr(udpsock_get_ipsock(udp), addr, addr_len,
&udp->udp_pcb->local_ip, udp->udp_pcb->local_port);
return OK;
}
/*
* Retrieve the remote socket address of a UDP socket.
*/
static int
udpsock_getpeername(struct sock * sock, struct sockaddr * addr,
socklen_t * addr_len)
{
struct udpsock *udp = (struct udpsock *)sock;
if (!udpsock_is_conn(udp))
return ENOTCONN;
ipsock_put_addr(udpsock_get_ipsock(udp), addr, addr_len,
&udp->udp_pcb->remote_ip, udp->udp_pcb->remote_port);
return OK;
}
/*
* Shut down a UDP socket for reading and/or writing.
*/
static int
udpsock_shutdown(struct sock * sock, unsigned int mask)
{
struct udpsock *udp = (struct udpsock *)sock;
if (mask & SFL_SHUT_RD)
udp_recv(udp->udp_pcb, NULL, NULL);
pktsock_shutdown(&udp->udp_pktsock, mask);
return OK;
}
/*
* Close a UDP socket.
*/
static int
udpsock_close(struct sock * sock, int force __unused)
{
struct udpsock *udp = (struct udpsock *)sock;
udp_recv(udp->udp_pcb, NULL, NULL);
udp_remove(udp->udp_pcb);
udp->udp_pcb = NULL;
pktsock_close(&udp->udp_pktsock);
return OK;
}
/*
* Free up a closed UDP socket.
*/
static void
udpsock_free(struct sock * sock)
{
struct udpsock *udp = (struct udpsock *)sock;
assert(udp->udp_pcb == NULL);
SIMPLEQ_INSERT_HEAD(&udp_freelist, udp, udp_next);
}
/*
* Fill the given kinfo_pcb sysctl(7) structure with information about the UDP
* PCB identified by the given pointer.
*/
static void
udpsock_get_info(struct kinfo_pcb * ki, const void * ptr)
{
const struct udp_pcb *pcb = (const struct udp_pcb *)ptr;
struct udpsock *udp;
ki->ki_type = SOCK_DGRAM;
/*
* All UDP sockets should be created by this module, but protect
* ourselves from the case that that is not true anyway.
*/
if (pcb->recv_arg != NULL) {
udp = (struct udpsock *)pcb->recv_arg;
assert(udp >= udp_array &&
udp < &udp_array[__arraycount(udp_array)]);
} else
udp = NULL;
ipsock_get_info(ki, &pcb->local_ip, pcb->local_port, &pcb->remote_ip,
pcb->remote_port);
if (udp != NULL) {
/* TODO: change this so that sockstat(1) may work one day. */
ki->ki_sockaddr = (uint64_t)(uintptr_t)udpsock_get_sock(udp);
ki->ki_rcvq = pktsock_get_recvlen(&udp->udp_pktsock);
}
}
/*
* Given either NULL or a previously returned UDP PCB pointer, return the first
* or next UDP PCB pointer, or NULL if there are no more. Skip UDP PCBs that
* are not bound to an address, as there is no use reporting them.
*/
static const void *
udpsock_enum(const void * last)
{
const struct udp_pcb *pcb;
if (last != NULL)
pcb = (const void *)((const struct udp_pcb *)last)->next;
else
pcb = (const void *)udp_pcbs;
while (pcb != NULL && pcb->local_port == 0)
pcb = pcb->next;
return pcb;
}
/*
* Obtain the list of UDP protocol control blocks, for sysctl(7).
*/
static ssize_t
udpsock_pcblist(struct rmib_call * call, struct rmib_node * node __unused,
struct rmib_oldp * oldp, struct rmib_newp * newp __unused)
{
return util_pcblist(call, oldp, udpsock_enum, udpsock_get_info);
}
static const struct sockevent_ops udpsock_ops = {
.sop_bind = udpsock_bind,
.sop_connect = udpsock_connect,
.sop_pre_send = udpsock_pre_send,
.sop_send = udpsock_send,
.sop_pre_recv = pktsock_pre_recv,
.sop_recv = pktsock_recv,
.sop_test_recv = pktsock_test_recv,
.sop_ioctl = ifconf_ioctl,
.sop_setsockmask = udpsock_setsockmask,
.sop_setsockopt = udpsock_setsockopt,
.sop_getsockopt = udpsock_getsockopt,
.sop_getsockname = udpsock_getsockname,
.sop_getpeername = udpsock_getpeername,
.sop_shutdown = udpsock_shutdown,
.sop_close = udpsock_close,
.sop_free = udpsock_free
};
0