forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlnksock.c
More file actions
77 lines (60 loc) · 1.67 KB
/
Copy pathlnksock.c
File metadata and controls
77 lines (60 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* LWIP service - lnksock.c - link sockets */
/*
* This module contains absolutely minimal support for AF_LINK type sockets,
* because for now we need them only to support a specific set of IOCTLs, as
* required by for example ifconfig(8).
*/
#include "lwip.h"
/* The number of link sockets. */
#define NR_LNKSOCK 4
static struct lnksock {
struct sock lnk_sock; /* socket object, MUST be first */
SIMPLEQ_ENTRY(lnksock) lnk_next; /* next in free list */
} lnk_array[NR_LNKSOCK];
static SIMPLEQ_HEAD(, lnksock) lnk_freelist; /* list of free link sockets */
static const struct sockevent_ops lnksock_ops;
/*
* Initialize the link sockets module.
*/
void
lnksock_init(void)
{
unsigned int slot;
/* Initialize the list of free link sockets. */
SIMPLEQ_INIT(&lnk_freelist);
for (slot = 0; slot < __arraycount(lnk_array); slot++)
SIMPLEQ_INSERT_TAIL(&lnk_freelist, &lnk_array[slot], lnk_next);
}
/*
* Create a link socket.
*/
sockid_t
lnksock_socket(int type, int protocol, struct sock ** sockp,
const struct sockevent_ops ** ops)
{
struct lnksock *lnk;
if (type != SOCK_DGRAM)
return EPROTOTYPE;
if (protocol != 0)
return EPROTONOSUPPORT;
if (SIMPLEQ_EMPTY(&lnk_freelist))
return ENOBUFS;
lnk = SIMPLEQ_FIRST(&lnk_freelist);
SIMPLEQ_REMOVE_HEAD(&lnk_freelist, lnk_next);
*sockp = &lnk->lnk_sock;
*ops = &lnksock_ops;
return SOCKID_LNK | (sockid_t)(lnk - lnk_array);
}
/*
* Free up a closed link socket.
*/
static void
lnksock_free(struct sock * sock)
{
struct lnksock *lnk = (struct lnksock *)sock;
SIMPLEQ_INSERT_HEAD(&lnk_freelist, lnk, lnk_next);
}
static const struct sockevent_ops lnksock_ops = {
.sop_ioctl = ifconf_ioctl,
.sop_free = lnksock_free
};