1 /* LWIP service - lnksock.c - link sockets */
3 * This module contains absolutely minimal support for AF_LINK type sockets,
4 * because for now we need them only to support a specific set of IOCTLs, as
5 * required by for example ifconfig(8).
10 /* The number of link sockets. */
13 static struct lnksock
{
14 struct sock lnk_sock
; /* socket object, MUST be first */
15 SIMPLEQ_ENTRY(lnksock
) lnk_next
; /* next in free list */
16 } lnk_array
[NR_LNKSOCK
];
18 static SIMPLEQ_HEAD(, lnksock
) lnk_freelist
; /* list of free link sockets */
20 static const struct sockevent_ops lnksock_ops
;
23 * Initialize the link sockets module.
30 /* Initialize the list of free link sockets. */
31 SIMPLEQ_INIT(&lnk_freelist
);
33 for (slot
= 0; slot
< __arraycount(lnk_array
); slot
++)
34 SIMPLEQ_INSERT_TAIL(&lnk_freelist
, &lnk_array
[slot
], lnk_next
);
38 * Create a link socket.
41 lnksock_socket(int type
, int protocol
, struct sock
** sockp
,
42 const struct sockevent_ops
** ops
)
46 if (type
!= SOCK_DGRAM
)
50 return EPROTONOSUPPORT
;
52 if (SIMPLEQ_EMPTY(&lnk_freelist
))
55 lnk
= SIMPLEQ_FIRST(&lnk_freelist
);
56 SIMPLEQ_REMOVE_HEAD(&lnk_freelist
, lnk_next
);
58 *sockp
= &lnk
->lnk_sock
;
60 return SOCKID_LNK
| (sockid_t
)(lnk
- lnk_array
);
64 * Free up a closed link socket.
67 lnksock_free(struct sock
* sock
)
69 struct lnksock
*lnk
= (struct lnksock
*)sock
;
71 SIMPLEQ_INSERT_HEAD(&lnk_freelist
, lnk
, lnk_next
);
74 static const struct sockevent_ops lnksock_ops
= {
75 .sop_ioctl
= ifconf_ioctl
,
76 .sop_free
= lnksock_free