File init.c changed (mode: 100644) (index 60a0113..90888b1) |
5 |
5 |
//****************************************************************************** |
//****************************************************************************** |
6 |
6 |
#include <ulinux/compiler_types.h> |
#include <ulinux/compiler_types.h> |
7 |
7 |
#include <ulinux/arch/sysc.h> |
#include <ulinux/arch/sysc.h> |
8 |
|
#ifdef DEBUG |
|
9 |
8 |
#include <ulinux/arch/types.h> |
#include <ulinux/arch/types.h> |
10 |
9 |
#include <ulinux/error.h> |
#include <ulinux/error.h> |
|
10 |
|
#include <ulinux/socket/socket.h> |
|
11 |
|
#include <ulinux/socket/netlink.h> |
|
12 |
|
#ifdef DEBUG |
11 |
13 |
#include <ulinux/file.h> |
#include <ulinux/file.h> |
12 |
14 |
#include <ulinux/stat.h> |
#include <ulinux/stat.h> |
13 |
15 |
#include <ulinux/mmap.h> |
#include <ulinux/mmap.h> |
|
... |
... |
k_u8 *g_dprintf_buf; |
25 |
27 |
k_i g_console; |
k_i g_console; |
26 |
28 |
#endif |
#endif |
27 |
29 |
|
|
|
30 |
|
static k_i uevent_sock; |
|
31 |
|
|
28 |
32 |
static void sigs_setup(void) |
static void sigs_setup(void) |
29 |
33 |
{ |
{ |
30 |
34 |
k_ul mask=(~0); |
k_ul mask=(~0); |
|
... |
... |
static void sigs_setup(void) |
35 |
39 |
} |
} |
36 |
40 |
} |
} |
37 |
41 |
|
|
|
42 |
|
static void uevent_setup(void) |
|
43 |
|
{ |
|
44 |
|
uevent_sock=(k_i)sysc(socket,3,K_PF_NETLINK,K_SOCK_RAW|K_SOCK_NONBLOCK, |
|
45 |
|
K_NETLINK_KOBJECT_UEVENT); |
|
46 |
|
if(K_ISERR(uevent_sock)){ |
|
47 |
|
OUT(PRE "ERROR:unable to create uevent netlink socket:%d\n",uevent_sock); |
|
48 |
|
sysc(exit_group,1,-1); |
|
49 |
|
} |
|
50 |
|
} |
|
51 |
|
|
38 |
52 |
void _start(void) |
void _start(void) |
39 |
53 |
{ |
{ |
40 |
54 |
# ifdef DEBUG |
# ifdef DEBUG |
41 |
|
k_l rl=sysc(open,3,"/dev/console",K_O_WRONLY,0); |
|
42 |
|
if(K_ISERR(rl)) sysc(exit_group,1,-1); |
|
43 |
|
g_console=(k_i)rl; |
|
44 |
|
rl=sysc(mmap,6,0, K_PAGE_SIZE, K_PROT_READ|K_PROT_WRITE, |
|
|
55 |
|
//FIXME:put the debug buffer in static section |
|
56 |
|
k_l r=sysc(open,3,"/dev/console",K_O_WRONLY,0); |
|
57 |
|
if(K_ISERR(r)) sysc(exit_group,1,-1); |
|
58 |
|
g_console=(k_i)r; |
|
59 |
|
r=sysc(mmap,6,0, K_PAGE_SIZE, K_PROT_READ|K_PROT_WRITE, |
45 |
60 |
K_MAP_PRIVATE|K_MAP_ANONYMOUS|K_MAP_POPULATE,0,0); |
K_MAP_PRIVATE|K_MAP_ANONYMOUS|K_MAP_POPULATE,0,0); |
46 |
|
if(K_ISERR(rl)){ |
|
|
61 |
|
if(K_ISERR(r)){ |
47 |
62 |
OUTC(PRE "ERROR:unable to mmap a memory page for formatted output\n"); |
OUTC(PRE "ERROR:unable to mmap a memory page for formatted output\n"); |
48 |
63 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
49 |
64 |
} |
} |
50 |
|
g_dprintf_buf=(k_u8*)rl;//just one page should be enough for formatted output |
|
|
65 |
|
g_dprintf_buf=(k_u8*)r;//just one page should be enough for formatted output |
51 |
66 |
# endif |
# endif |
52 |
67 |
sigs_setup(); |
sigs_setup(); |
|
68 |
|
uevent_setup(); |
53 |
69 |
modules_load(); |
modules_load(); |
54 |
70 |
sysc(exit_group,1,0); |
sysc(exit_group,1,0); |
55 |
71 |
} |
} |
File makefile changed (mode: 100644) (index 3e39461..a47a4aa) |
1 |
1 |
include conf.mk |
include conf.mk |
2 |
2 |
|
|
3 |
|
.PHONY:all dirs clean am_i_root help |
|
|
3 |
|
.PHONY:all dirs clean am_i_root help uevent_monitor |
4 |
4 |
|
|
5 |
5 |
DIRS=\ |
DIRS=\ |
6 |
6 |
$(OBJ_DIR) \ |
$(OBJ_DIR) \ |
|
... |
... |
OBJS+= $(ULINUX_DEBUG_OBJS) |
21 |
21 |
endif |
endif |
22 |
22 |
|
|
23 |
23 |
help: |
help: |
24 |
|
@echo "targets are 'all', 'help'(this output), 'clean'" |
|
|
24 |
|
@echo "targets are 'all', 'help'(this output), 'clean', 'uevent_monitor'" |
25 |
25 |
@echo -e "you can configure the build with the following variables:\\n\ |
@echo -e "you can configure the build with the following variables:\\n\ |
26 |
26 |
SYSROOT, KERNEL_VERSION, ARCH, MODULES, SCSI_WAIT, CC, LD, CFLAGS, LDFLAGS\\n\ |
SYSROOT, KERNEL_VERSION, ARCH, MODULES, SCSI_WAIT, CC, LD, CFLAGS, LDFLAGS\\n\ |
27 |
27 |
(you can tune the conf.mk file)" |
(you can tune the conf.mk file)" |
|
... |
... |
clean: |
79 |
79 |
-rm -f ulinux/arch |
-rm -f ulinux/arch |
80 |
80 |
-rm -Rf $(BUILD_DIR) |
-rm -Rf $(BUILD_DIR) |
81 |
81 |
-rm -f modules_list.h |
-rm -f modules_list.h |
|
82 |
|
|
|
83 |
|
#=============================================================================== |
|
84 |
|
$(BUILD_DIR)/uevent_monitor:uevent_monitor.c $(ULINUX_DEBUG_OBJS) |
|
85 |
|
$(CC) $(CFLAGS) -c $< -o /tmp/uevent_monitor.o |
|
86 |
|
$(LD) $(LDFLAGS) /tmp/uevent_monitor.o $(ULINUX_DEBUG_OBJS) --output $@ |
|
87 |
|
|
|
88 |
|
uevent_monitor:dirs ulinux/arch $(BUILD_DIR)/uevent_monitor |
|
89 |
|
#=============================================================================== |
File uevent_monitor.c added (mode: 100644) (index 0000000..359a60e) |
|
1 |
|
#include <ulinux/compiler_types.h> |
|
2 |
|
#include <ulinux/arch/sysc.h> |
|
3 |
|
#include <ulinux/arch/types.h> |
|
4 |
|
#include <ulinux/error.h> |
|
5 |
|
#include <ulinux/file.h> |
|
6 |
|
#include <ulinux/stat.h> |
|
7 |
|
#include <ulinux/mmap.h> |
|
8 |
|
#include <ulinux/signal/signal.h> |
|
9 |
|
#include <ulinux/socket/socket.h> |
|
10 |
|
#include <ulinux/socket/msg.h> |
|
11 |
|
#include <ulinux/socket/netlink.h> |
|
12 |
|
#include <ulinux/epoll.h> |
|
13 |
|
#include <stdarg.h> |
|
14 |
|
#include <ulinux/utils/ascii/string/vsprintf.h> |
|
15 |
|
#include <ulinux/utils/mem.h> |
|
16 |
|
|
|
17 |
|
//XXX:what udev does in extra |
|
18 |
|
// - it force overides the kernel socket buffer size to 128 MB (then 256 MB) |
|
19 |
|
// - it checks on socket credential |
|
20 |
|
// - it checks the netlink sender is 0 (kernel) |
|
21 |
|
// - it uses the socket filter |
|
22 |
|
|
|
23 |
|
#define DPRINTF_BUF_SZ 1024 |
|
24 |
|
static k_u8 *g_dprintf_buf; |
|
25 |
|
#define ERR(f,...) u_a_dprintf(2,g_dprintf_buf,DPRINTF_BUF_SZ,(k_u8*)f,\ |
|
26 |
|
__VA_ARGS__) |
|
27 |
|
#define ERRC(s) sysc(write,3,2,s,sizeof(s)) |
|
28 |
|
|
|
29 |
|
static void uevent_rcv(k_i s) |
|
30 |
|
{ |
|
31 |
|
k_u8 buf[8192]; |
|
32 |
|
u_memset(buf,0,sizeof(buf)); |
|
33 |
|
|
|
34 |
|
struct k_io_vec io_vec; |
|
35 |
|
io_vec.base=buf; |
|
36 |
|
io_vec.len=sizeof(buf); |
|
37 |
|
|
|
38 |
|
struct k_msg_hdr msg; |
|
39 |
|
u_memset(&msg,0,sizeof(msg)); |
|
40 |
|
msg.iov=&io_vec; |
|
41 |
|
msg.iov_len=1; |
|
42 |
|
|
|
43 |
|
k_l r; |
|
44 |
|
do{ |
|
45 |
|
r=sysc(recvmsg,3,s,&msg,0); |
|
46 |
|
}while(r==-K_EINTR); |
|
47 |
|
if(K_ISERR(r)){ |
|
48 |
|
ERR("ERROR:unable to receive the uevent(%ld)\n",r); |
|
49 |
|
sysc(exit_group,1,-1); |
|
50 |
|
} |
|
51 |
|
if(msg.flgs&K_MSG_TRUNC){ |
|
52 |
|
ERR("ERROR:the uevent was truncated(flags=0x%x)\n",msg.flgs); |
|
53 |
|
sysc(exit_group,1,-1); |
|
54 |
|
} |
|
55 |
|
ERRC("uevent received:\n"); |
|
56 |
|
k_i len=r; |
|
57 |
|
k_u8 *p=&buf[0]; |
|
58 |
|
while(len){ |
|
59 |
|
if(*p) ERR("%c",*p); else ERRC("\n"); |
|
60 |
|
++p; |
|
61 |
|
len--; |
|
62 |
|
} |
|
63 |
|
ERRC("\n"); |
|
64 |
|
} |
|
65 |
|
|
|
66 |
|
void _start(void) |
|
67 |
|
{ |
|
68 |
|
static k_u8 dprintf_buf[DPRINTF_BUF_SZ]; |
|
69 |
|
g_dprintf_buf=&dprintf_buf[0]; |
|
70 |
|
|
|
71 |
|
//---------------------------------------------------------------------------- |
|
72 |
|
|
|
73 |
|
k_i ep_fd=(k_i)sysc(epoll_create1,1,0); |
|
74 |
|
if(K_ISERR(ep_fd)){ |
|
75 |
|
ERR("FATAL:unable to create epoll fd (%d)\n",ep_fd); |
|
76 |
|
sysc(exit_group,1,-1); |
|
77 |
|
} |
|
78 |
|
|
|
79 |
|
//---------------------------------------------------------------------------- |
|
80 |
|
|
|
81 |
|
k_i s=(k_i)sysc(socket,3,K_PF_NETLINK,K_SOCK_RAW|K_SOCK_NONBLOCK, |
|
82 |
|
K_NETLINK_KOBJECT_UEVENT); |
|
83 |
|
if(K_ISERR(s)){ |
|
84 |
|
ERR("ERROR:unable to uevent netlink socket:%d\n",s); |
|
85 |
|
sysc(exit_group,1,-1); |
|
86 |
|
} |
|
87 |
|
|
|
88 |
|
//---------------------------------------------------------------------------- |
|
89 |
|
|
|
90 |
|
//uevent groups? only one: 1 |
|
91 |
|
struct k_sockaddr_nl addr={K_AF_NETLINK,0,0,1}; |
|
92 |
|
k_l r=sysc(bind,3,s,&addr,sizeof(addr)); |
|
93 |
|
if(K_ISERR(r)){ |
|
94 |
|
ERR("ERROR:unable to bind address to uevent netlink socket:%ld\n",r); |
|
95 |
|
sysc(exit_group,1,-1); |
|
96 |
|
} |
|
97 |
|
|
|
98 |
|
//---------------------------------------------------------------------------- |
|
99 |
|
|
|
100 |
|
struct k_epoll_event ep_evt; |
|
101 |
|
u_memset(&ep_evt,0,sizeof(ep_evt)); |
|
102 |
|
ep_evt.events=K_EPOLLIN; |
|
103 |
|
ep_evt.data.fd=s; |
|
104 |
|
r=sysc(epoll_ctl,4,ep_fd,K_EPOLL_CTL_ADD,s,&ep_evt); |
|
105 |
|
if(K_ISERR(r)){ |
|
106 |
|
ERR("ERROR:unable to register uevent netlink socket to epoll (%ld)\n",r); |
|
107 |
|
sysc(exit_group,1,-1); |
|
108 |
|
} |
|
109 |
|
|
|
110 |
|
//---------------------------------------------------------------------------- |
|
111 |
|
// |
|
112 |
|
while(1){ |
|
113 |
|
static struct k_epoll_event evts[1];//uevent netlink event |
|
114 |
|
do{ |
|
115 |
|
u_memset(evts,0,sizeof(evts)); |
|
116 |
|
r=sysc(epoll_wait,4,ep_fd,evts,1,-1); |
|
117 |
|
}while(r==-K_EINTR); |
|
118 |
|
if(K_ISERR(r)){ |
|
119 |
|
ERR("FATAL:error epolling fds (%ld)\n",r); |
|
120 |
|
sysc(exit_group,1,-1); |
|
121 |
|
} |
|
122 |
|
k_l i=0; |
|
123 |
|
while(i<r){ |
|
124 |
|
if(evts[i].data.fd==s){ |
|
125 |
|
if(evts[i].events&K_EPOLLIN){ |
|
126 |
|
uevent_rcv(s); |
|
127 |
|
}else{ |
|
128 |
|
ERR("ERROR:unmanaged epolling event on uevent netlink socket" |
|
129 |
|
" n=%ld events=%u\n", i,evts[i].events); |
|
130 |
|
sysc(exit_group,1,-1); |
|
131 |
|
} |
|
132 |
|
} |
|
133 |
|
++i; |
|
134 |
|
} |
|
135 |
|
} |
|
136 |
|
sysc(exit_group,1,0); |
|
137 |
|
} |
File ulinux/socket/msg.h changed (mode: 100644) (index e1d2ae2..6945e51) |
1 |
|
//********************************************************************************************** |
|
2 |
|
//*this code is protected by the GNU affero GPLv3 |
|
3 |
|
//*author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com) |
|
4 |
|
//********************************************************************************************** |
|
5 |
1 |
#ifndef ULINUX_SOCKET_MSG_H |
#ifndef ULINUX_SOCKET_MSG_H |
6 |
2 |
#define ULINUX_SOCKET_MSG_H |
#define ULINUX_SOCKET_MSG_H |
|
3 |
|
//****************************************************************************** |
|
4 |
|
//*this code is protected by the GNU affero GPLv3 |
|
5 |
|
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
6 |
|
//* <digital.ragnarok AT gmail dot com> |
|
7 |
|
//****************************************************************************** |
7 |
8 |
#define K_SOL_SOCKET 1 |
#define K_SOL_SOCKET 1 |
8 |
9 |
|
|
9 |
|
struct k_iovec{//will probably go somewhere else proper kernel facilities are used |
|
10 |
|
void *iov_base;//BSD uses caddr_t (1003.1g requires void *) |
|
11 |
|
k_sz iov_len; //Must be size_t (1003.1g) |
|
|
10 |
|
struct k_io_vec{//will probably go somewhere else |
|
11 |
|
void *base;//BSD uses caddr_t (1003.1g requires void *) |
|
12 |
|
k_sz len; //Must be size_t (1003.1g) |
12 |
13 |
}; |
}; |
13 |
14 |
|
|
14 |
|
struct k_msghdr{ |
|
15 |
|
void *msg_name; //socket name |
|
16 |
|
k_i msg_namelen; //length of name |
|
17 |
|
struct k_iovec *msg_iov; //data blocks |
|
18 |
|
k_sz msg_iovlen; //number of blocks |
|
19 |
|
void *msg_control; //per protocol magic (eg BSD file descriptor passing) |
|
20 |
|
k_sz msg_controllen;//length of cmsg list |
|
21 |
|
k_u msg_flags; |
|
|
15 |
|
struct k_msg_hdr{ |
|
16 |
|
void *name;//socket name |
|
17 |
|
k_i name_len;//length of name |
|
18 |
|
struct k_io_vec *iov;//data blocks |
|
19 |
|
k_sz iov_len;//number of blocks |
|
20 |
|
void *control;//per protocol magic (eg BSD file descriptor passing) |
|
21 |
|
k_sz control_len;//length of cmsg list |
|
22 |
|
k_u flgs; |
22 |
23 |
}; |
}; |
23 |
24 |
|
|
24 |
|
struct k_cmsghdr{ |
|
25 |
|
k_sz cmsg_len; //data byte count, including hdr |
|
26 |
|
k_i cmsg_level;//originating protocol |
|
27 |
|
k_i cmsg_type; //protocol-specific type |
|
|
25 |
|
//the c prefix stands for access *c*ontrol message (other name ancillary data) |
|
26 |
|
struct k_cmsg_hdr{ |
|
27 |
|
k_sz len;//data byte count, including hdr |
|
28 |
|
k_i lvl;//originating protocol |
|
29 |
|
k_i type;//protocol-specific type |
28 |
30 |
}; |
}; |
29 |
31 |
|
|
30 |
32 |
#define __K_CMSG_NXTHDR(ctl,len,cmsg) __k_cmsg_nxthdr((ctl),(len),(cmsg)) |
#define __K_CMSG_NXTHDR(ctl,len,cmsg) __k_cmsg_nxthdr((ctl),(len),(cmsg)) |
|
... |
... |
struct k_cmsghdr{ |
32 |
34 |
|
|
33 |
35 |
#define K_CMSG_ALIGN(len) (((len)+sizeof(k_l)-1)&~(sizeof(k_l)-1)) |
#define K_CMSG_ALIGN(len) (((len)+sizeof(k_l)-1)&~(sizeof(k_l)-1)) |
34 |
36 |
|
|
35 |
|
#define K_CMSG_DATA(cmsg) ((void*)((k_u8*)(cmsg)+K_CMSG_ALIGN(sizeof(struct k_cmsghdr)))) |
|
36 |
|
#define K_CMSG_SPACE(len) (K_CMSG_ALIGN(sizeof(struct k_cmsghdr))+K_CMSG_ALIGN(len)) |
|
37 |
|
#define K_CMSG_LEN(len) (K_CMSG_ALIGN(sizeof(struct k_cmsghdr))+(len)) |
|
|
37 |
|
#define K_CMSG_DATA(cmsg) ((void*)((k_u8*)(cmsg)+K_CMSG_ALIGN(\ |
|
38 |
|
sizeof(struct k_cmsg_hdr)))) |
|
39 |
|
#define K_CMSG_SPACE(len) (K_CMSG_ALIGN(sizeof(struct k_cmsg_hdr))\ |
|
40 |
|
+K_CMSG_ALIGN(len)) |
|
41 |
|
#define K_CMSG_LEN(len) (K_CMSG_ALIGN(sizeof(struct k_cmsg_hdr))+(len)) |
38 |
42 |
|
|
39 |
|
#define __K_CMSG_FIRSTHDR(ctl,len) ((len)>=sizeof(struct k_cmsghdr) ? \ |
|
40 |
|
(struct k_cmsghdr *)(ctl) : \ |
|
41 |
|
(struct k_cmsghdr *)NULL) |
|
42 |
|
#define K_CMSG_FIRSTHDR(msg) __K_CMSG_FIRSTHDR((msg)->msg_control,(msg)->msg_controllen) |
|
43 |
|
#define K_CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len>=sizeof(struct cmsghdr)&&\ |
|
|
43 |
|
#define __K_CMSG_FIRSTHDR(ctl,len) ((len)>=sizeof(struct k_cmsg_hdr) ? \ |
|
44 |
|
(struct k_cmsg_hdr *)(ctl) : \ |
|
45 |
|
(struct k_cmsg_hdr *)NULL) |
|
46 |
|
#define K_CMSG_FIRSTHDR(msg) __K_CMSG_FIRSTHDR((msg)->msg_control,\ |
|
47 |
|
(msg)->msg_controllen) |
|
48 |
|
#define K_CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len>=sizeof(struct cmsg_hdr)&&\ |
44 |
49 |
(cmsg)->cmsg_len<=(k_ul)\ |
(cmsg)->cmsg_len<=(k_ul)\ |
45 |
50 |
((mhdr)->msg_controllen-\ |
((mhdr)->msg_controllen-\ |
46 |
51 |
((k_u8*)(cmsg)-(k_u8*)(mhdr)->msg_control))) |
((k_u8*)(cmsg)-(k_u8*)(mhdr)->msg_control))) |
47 |
52 |
|
|
48 |
|
static inline struct k_cmsghdr * __k_cmsg_nxthdr(void *ctl,k_sz size,struct k_cmsghdr *cmsg) |
|
|
53 |
|
static inline struct k_cmsg_hdr * __k_cmsg_nxthdr(void *ctl,k_sz size, |
|
54 |
|
struct k_cmsg_hdr *cmsg) |
49 |
55 |
{ |
{ |
50 |
|
struct k_cmsghdr *ptr; |
|
|
56 |
|
struct k_cmsg_hdr *ptr; |
51 |
57 |
|
|
52 |
|
ptr=(struct k_cmsghdr*)(((k_u8*)cmsg)+K_CMSG_ALIGN(cmsg->cmsg_len)); |
|
53 |
|
if((k_ul)((k_u8*)(ptr+1)-(k_u8*)ctl)>size) return (struct k_cmsghdr *)0; |
|
|
58 |
|
ptr=(struct k_cmsg_hdr*)(((k_u8*)cmsg)+K_CMSG_ALIGN(cmsg->len)); |
|
59 |
|
if((k_ul)((k_u8*)(ptr+1)-(k_u8*)ctl)>size) return (struct k_cmsg_hdr *)0; |
54 |
60 |
return ptr; |
return ptr; |
55 |
61 |
} |
} |
56 |
62 |
|
|
57 |
|
static inline struct k_cmsghdr *k_cmsg_nxthdr(struct k_msghdr *msg,struct k_cmsghdr *cmsg) |
|
|
63 |
|
static inline struct k_cmsg_hdr *k_cmsg_nxthdr(struct k_msg_hdr *msg, |
|
64 |
|
struct k_cmsg_hdr *cmsg) |
58 |
65 |
{ |
{ |
59 |
|
return __k_cmsg_nxthdr(msg->msg_control,msg->msg_controllen,cmsg); |
|
|
66 |
|
return __k_cmsg_nxthdr(msg->control,msg->control_len,cmsg); |
60 |
67 |
} |
} |
61 |
68 |
|
|
62 |
|
#define K_MSG_CTRUNC 8 |
|
63 |
|
#define K_SCM_RIGHTS 0x01//rw: access rights (array of int) |
|
|
69 |
|
#define K_MSG_OOB 1 |
|
70 |
|
#define K_MSG_PEEK 2 |
|
71 |
|
#define K_MSG_DONTROUTE 4 |
|
72 |
|
#define K_MSG_TRYHARD 4//synonym for msg_dontroute for decnet |
|
73 |
|
#define K_MSG_CTRUNC 8 |
|
74 |
|
#define K_MSG_PROBE 0x10//do not send. only probe path f.e. for mtu |
|
75 |
|
#define K_MSG_TRUNC 0x20 |
|
76 |
|
#define K_MSG_DONTWAIT 0x40//nonblocking io |
|
77 |
|
#define K_MSG_EOR 0x80//end of record |
|
78 |
|
#define K_MSG_WAITALL 0x100//wait for a full request |
|
79 |
|
#define K_MSG_FIN 0x200 |
|
80 |
|
#define K_MSG_SYN 0x400 |
|
81 |
|
#define K_MSG_CONFIRM 0x800//confirm path validity |
|
82 |
|
#define K_MSG_RST 0x1000 |
|
83 |
|
#define K_MSG_ERRQUEUE 0x2000//fetch message from error queue |
|
84 |
|
#define K_MSG_NOSIGNAL 0x4000//do not generate sigpipe |
|
85 |
|
#define K_MSG_MORE 0x8000//sender will send more |
|
86 |
|
#define K_MSG_WAITFORONE 0x10000//recvmmsg(): block until 1+ packets avail |
|
87 |
|
#define K_MSG_EOF K_MSG_FIN |
|
88 |
|
#define K_MSG_CMSG_CLOEXEC 0x40000000//set close_on_exit for file descriptor |
|
89 |
|
//received through scm_rights |
|
90 |
|
|
|
91 |
|
//"socket"-level control message types: |
|
92 |
|
#define K_SCM_RIGHTS 0x01//rw: access rights (array of int) |
|
93 |
|
#define K_SCM_CREDENTIALS 0x02//rw: struct ucred |
|
94 |
|
#define K_SCM_SECURITY 0x03//rw: security label |
|
95 |
|
struct ucred{ |
|
96 |
|
k_u32 pid; |
|
97 |
|
k_u32 uid; |
|
98 |
|
k_u32 gid; |
|
99 |
|
}; |
64 |
100 |
#endif |
#endif |
File ulinux/socket/netlink.h added (mode: 100644) (index 0000000..88775d0) |
|
1 |
|
#ifndef ULINUX_SOCKET_NETLINK_H |
|
2 |
|
#define ULINUX_SOCKET_NETLINK_H |
|
3 |
|
//****************************************************************************** |
|
4 |
|
//*this code is protected by the GNU affero GPLv3 |
|
5 |
|
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
6 |
|
//* <digital.ragnarok AT gmail dot com> |
|
7 |
|
//****************************************************************************** |
|
8 |
|
#define K_NETLINK_ROUTE 0//routing/device hook |
|
9 |
|
#define K_NETLINK_UNUSED 1//unused number |
|
10 |
|
#define K_NETLINK_USERSOCK 2//reserved for user mode socket protocols |
|
11 |
|
#define K_NETLINK_FIREWALL 3//firewalling hook |
|
12 |
|
#define K_NETLINK_INET_DIAG 4//inet socket monitoring |
|
13 |
|
#define K_NETLINK_NFLOG 5//netfilter/iptables ulog |
|
14 |
|
#define K_NETLINK_XFRM 6//ipsec |
|
15 |
|
#define K_NETLINK_SELINUX 7//selinux event notifications |
|
16 |
|
#define K_NETLINK_ISCSI 8//open-iscsi |
|
17 |
|
#define K_NETLINK_AUDIT 9//auditing |
|
18 |
|
#define K_NETLINK_FIB_LOOKUP 10 |
|
19 |
|
#define K_NETLINK_CONNECTOR 11 |
|
20 |
|
#define K_NETLINK_NETFILTER 12//netfilter subsystem |
|
21 |
|
#define K_NETLINK_IP6_FW 13 |
|
22 |
|
#define K_NETLINK_DNRTMSG 14//decnet routing messages |
|
23 |
|
#define K_NETLINK_KOBJECT_UEVENT 15//kernel messages to userspace |
|
24 |
|
#define K_NETLINK_GENERIC 16 |
|
25 |
|
//leave room for netlink_dm (dm events) |
|
26 |
|
#define K_NETLINK_SCSITRANSPORT 18//scsi transports |
|
27 |
|
#define K_NETLINK_ECRYPTFS 19 |
|
28 |
|
#define K_NETLINK_RDMA 20 |
|
29 |
|
#define K_MAX_LINKS 32 |
|
30 |
|
|
|
31 |
|
struct k_sockaddr_nl{ |
|
32 |
|
k_us nl_family;//AF_NETLINK |
|
33 |
|
k_us nl_pad;//zero |
|
34 |
|
k_u32 nl_pid;//*port* id |
|
35 |
|
k_u32 nl_groups;//multicast groups mask |
|
36 |
|
//padding on __SOCK_ADDR_SZ__ in 0 |
|
37 |
|
}; |
|
38 |
|
|
|
39 |
|
struct k_nl_msg_hdr{ |
|
40 |
|
k_u32 len;//length of message including header |
|
41 |
|
k_u16 type;//message content |
|
42 |
|
k_u16 flgs;//additional flags |
|
43 |
|
k_u32 seq;//sequence number |
|
44 |
|
k_u32 pid;//sending process port id |
|
45 |
|
}; |
|
46 |
|
|
|
47 |
|
//flags values |
|
48 |
|
#define K_NLM_F_REQUEST 1//it is request message |
|
49 |
|
#define K_NLM_F_MULTI 2//multipart message, terminated by nlmsg_done |
|
50 |
|
#define K_NLM_F_ACK 4//reply with ack, with zero or error code |
|
51 |
|
#define K_NLM_F_ECHO 8//echo this request |
|
52 |
|
#define K_NLM_F_DUMP_INTR 16//dump was inconsistent due to sequence change |
|
53 |
|
|
|
54 |
|
//modifiers to get request |
|
55 |
|
#define K_NLM_F_ROOT 0x100//specify tree root |
|
56 |
|
#define K_NLM_F_MATCH 0x200//return all matching |
|
57 |
|
#define K_NLM_F_ATOMIC 0x400//atomic get |
|
58 |
|
#define K_NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH) |
|
59 |
|
|
|
60 |
|
//modifiers to new request |
|
61 |
|
#define K_NLM_F_REPLACE 0x100//override existing |
|
62 |
|
#define K_NLM_F_EXCL 0x200//do not touch, if it exists |
|
63 |
|
#define K_NLM_F_CREATE 0x400//create, if it does not exist |
|
64 |
|
#define K_NLM_F_APPEND 0x800//add to end of list |
|
65 |
|
|
|
66 |
|
#define K_NLMSG_ALIGNTO 4U |
|
67 |
|
#define K_NLMSG_ALIGN(len) (((len)+K_NLMSG_ALIGNTO-1)&~(K_NLMSG_ALIGNTO-1)) |
|
68 |
|
#define K_NLMSG_HDRLEN ((k_i)K_NLMSG_ALIGN(sizeof(struct k_nl_msg_hdr))) |
|
69 |
|
#define K_NLMSG_LENGTH(len) ((len)+K_NLMSG_ALIGN(K_NLMSG_HDRLEN)) |
|
70 |
|
#define K_NLMSG_SPACE(len) K_NLMSG_ALIGN(K_NLMSG_LENGTH(len)) |
|
71 |
|
#define K_NLMSG_DATA(nlh) ((void*)(((k_ut*)nlh)+K_NLMSG_LENGTH(0))) |
|
72 |
|
#define K_NLMSG_NEXT(nlh,len) ((len)-=K_NLMSG_ALIGN((nlh)->len),\ |
|
73 |
|
(struct k_nl_msg_hdr*)(((k_ut*)(nlh))\ |
|
74 |
|
+K_NLMSG_ALIGN((nlh)->len))) |
|
75 |
|
#define K_NLMSG_OK(nlh,len) ((len)>=(k_i)sizeof(struct k_nl_msg_hdr)\ |
|
76 |
|
&&(nlh)->len>=sizeof(struct k_nl_msg_hdr)\ |
|
77 |
|
&&(nlh)->len<=(len)) |
|
78 |
|
#define K_NLMSG_PAYLOAD(nlh,len) ((nlh)->len-K_NLMSG_SPACE((len))) |
|
79 |
|
|
|
80 |
|
#define K_NLMSG_NOOP 0x1//nothing |
|
81 |
|
#define K_NLMSG_ERROR 0x2//error |
|
82 |
|
#define K_NLMSG_DONE 0x3//end of a dump |
|
83 |
|
#define K_NLMSG_OVERRUN 0x4//data lost |
|
84 |
|
#define K_NLMSG_MIN_TYPE 0x10//<0x10:reserved control messages |
|
85 |
|
|
|
86 |
|
struct k_nl_msg_err{ |
|
87 |
|
k_i error; |
|
88 |
|
struct k_nl_msg_hdr msg; |
|
89 |
|
}; |
|
90 |
|
#endif |
File ulinux/socket/socket.h changed (mode: 100644) (index 53c328f..5839831) |
1 |
|
//********************************************************************************************** |
|
2 |
|
//*this code is protected by the GNU affero GPLv3 |
|
3 |
|
//*author:Sylvain BERTRAND (sylvain.bertrand AT gmail dot com) |
|
4 |
|
//********************************************************************************************** |
|
5 |
1 |
#ifndef ULINUX_SOCKET_SOCKET_H |
#ifndef ULINUX_SOCKET_SOCKET_H |
6 |
2 |
#define ULINUX_SOCKET_SOCKET_H |
#define ULINUX_SOCKET_SOCKET_H |
7 |
|
struct k_in_addr{k_u32 s_addr;}; |
|
8 |
|
|
|
9 |
|
#define __SOCK_SIZE__ 16//sizeof(struct sockaddr) |
|
10 |
|
struct k_sockaddr_in{ |
|
11 |
|
k_us sin_family;//address family |
|
12 |
|
k_u16 sin_port;//port number |
|
13 |
|
struct k_in_addr sin_addr;//internet address |
|
14 |
|
|
|
15 |
|
//pad to size of `struct sockaddr' |
|
16 |
|
k_u8 __pad[__SOCK_SIZE__-sizeof(k_s)-sizeof(k_us)-sizeof(struct k_in_addr)]; |
|
17 |
|
}; |
|
|
3 |
|
//****************************************************************************** |
|
4 |
|
//*this code is protected by the GNU affero GPLv3 |
|
5 |
|
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
6 |
|
//* <digital.ragnarok AT gmail dot com> |
|
7 |
|
//****************************************************************************** |
|
8 |
|
#define __SOCK_ADDR_SZ__ 16//sizeof(struct sockaddr) |
18 |
9 |
|
|
19 |
10 |
#define K_AF_UNSPEC 0 |
#define K_AF_UNSPEC 0 |
20 |
11 |
#define K_AF_UNIX 1//Unix domain sockets |
#define K_AF_UNIX 1//Unix domain sockets |
|
... |
... |
enum k_sock_type{ |
109 |
100 |
|
|
110 |
101 |
#define K_SOCK_NONBLOCK K_O_NONBLOCK |
#define K_SOCK_NONBLOCK K_O_NONBLOCK |
111 |
102 |
|
|
112 |
|
//XXX:should go in a IPv4 section |
|
113 |
|
#define K_INADDR_ANY ((k_ul)0x00000000) |
|
114 |
|
|
|
115 |
|
//---------------------------------------------------------------------------------------------- |
|
|
103 |
|
//------------------------------------------------------------------------------ |
116 |
104 |
//options |
//options |
117 |
|
//---------------------------------------------------------------------------------------------- |
|
|
105 |
|
//------------------------------------------------------------------------------ |
118 |
106 |
#define K_SOL_SOCKET 1//for setsockopt(2) |
#define K_SOL_SOCKET 1//for setsockopt(2) |
119 |
107 |
|
|
120 |
108 |
#define K_SO_DEBUG 1 |
#define K_SO_DEBUG 1 |
|
... |
... |
enum k_sock_type{ |
172 |
160 |
#define K_SO_DOMAIN 39 |
#define K_SO_DOMAIN 39 |
173 |
161 |
|
|
174 |
162 |
#define K_SO_RXQ_OVFL 40 |
#define K_SO_RXQ_OVFL 40 |
175 |
|
//---------------------------------------------------------------------------------------------- |
|
|
163 |
|
//------------------------------------------------------------------------------ |
176 |
164 |
#endif |
#endif |