1 |
1275 |
phoenix |
#ifndef __LINUX_NETLINK_H
|
2 |
|
|
#define __LINUX_NETLINK_H
|
3 |
|
|
|
4 |
|
|
#define NETLINK_ROUTE 0 /* Routing/device hook */
|
5 |
|
|
#define NETLINK_SKIP 1 /* Reserved for ENskip */
|
6 |
|
|
#define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */
|
7 |
|
|
#define NETLINK_FIREWALL 3 /* Firewalling hook */
|
8 |
|
|
#define NETLINK_TCPDIAG 4 /* TCP socket monitoring */
|
9 |
|
|
#define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */
|
10 |
|
|
#define NETLINK_ARPD 8
|
11 |
|
|
#define NETLINK_ROUTE6 11 /* af_inet6 route comm channel */
|
12 |
|
|
#define NETLINK_IP6_FW 13
|
13 |
|
|
#define NETLINK_DNRTMSG 14 /* DECnet routing messages */
|
14 |
|
|
#define NETLINK_TAPBASE 16 /* 16 to 31 are ethertap */
|
15 |
|
|
|
16 |
|
|
#define MAX_LINKS 32
|
17 |
|
|
|
18 |
|
|
struct sockaddr_nl
|
19 |
|
|
{
|
20 |
|
|
sa_family_t nl_family; /* AF_NETLINK */
|
21 |
|
|
unsigned short nl_pad; /* zero */
|
22 |
|
|
__u32 nl_pid; /* process pid */
|
23 |
|
|
__u32 nl_groups; /* multicast groups mask */
|
24 |
|
|
};
|
25 |
|
|
|
26 |
|
|
struct nlmsghdr
|
27 |
|
|
{
|
28 |
|
|
__u32 nlmsg_len; /* Length of message including header */
|
29 |
|
|
__u16 nlmsg_type; /* Message content */
|
30 |
|
|
__u16 nlmsg_flags; /* Additional flags */
|
31 |
|
|
__u32 nlmsg_seq; /* Sequence number */
|
32 |
|
|
__u32 nlmsg_pid; /* Sending process PID */
|
33 |
|
|
};
|
34 |
|
|
|
35 |
|
|
/* Flags values */
|
36 |
|
|
|
37 |
|
|
#define NLM_F_REQUEST 1 /* It is request message. */
|
38 |
|
|
#define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */
|
39 |
|
|
#define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
|
40 |
|
|
#define NLM_F_ECHO 8 /* Echo this request */
|
41 |
|
|
|
42 |
|
|
/* Modifiers to GET request */
|
43 |
|
|
#define NLM_F_ROOT 0x100 /* specify tree root */
|
44 |
|
|
#define NLM_F_MATCH 0x200 /* return all matching */
|
45 |
|
|
#define NLM_F_ATOMIC 0x400 /* atomic GET */
|
46 |
|
|
#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
|
47 |
|
|
|
48 |
|
|
/* Modifiers to NEW request */
|
49 |
|
|
#define NLM_F_REPLACE 0x100 /* Override existing */
|
50 |
|
|
#define NLM_F_EXCL 0x200 /* Do not touch, if it exists */
|
51 |
|
|
#define NLM_F_CREATE 0x400 /* Create, if it does not exist */
|
52 |
|
|
#define NLM_F_APPEND 0x800 /* Add to end of list */
|
53 |
|
|
|
54 |
|
|
/*
|
55 |
|
|
4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL
|
56 |
|
|
4.4BSD CHANGE NLM_F_REPLACE
|
57 |
|
|
|
58 |
|
|
True CHANGE NLM_F_CREATE|NLM_F_REPLACE
|
59 |
|
|
Append NLM_F_CREATE
|
60 |
|
|
Check NLM_F_EXCL
|
61 |
|
|
*/
|
62 |
|
|
|
63 |
|
|
#define NLMSG_ALIGNTO 4
|
64 |
|
|
#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
|
65 |
|
|
#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr)))
|
66 |
|
|
#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
|
67 |
|
|
#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
|
68 |
|
|
#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
|
69 |
|
|
(struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
|
70 |
|
|
#define NLMSG_OK(nlh,len) ((len) > 0 && (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
|
71 |
|
|
(nlh)->nlmsg_len <= (len))
|
72 |
|
|
#define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
|
73 |
|
|
|
74 |
|
|
#define NLMSG_NOOP 0x1 /* Nothing. */
|
75 |
|
|
#define NLMSG_ERROR 0x2 /* Error */
|
76 |
|
|
#define NLMSG_DONE 0x3 /* End of a dump */
|
77 |
|
|
#define NLMSG_OVERRUN 0x4 /* Data lost */
|
78 |
|
|
|
79 |
|
|
struct nlmsgerr
|
80 |
|
|
{
|
81 |
|
|
int error;
|
82 |
|
|
struct nlmsghdr msg;
|
83 |
|
|
};
|
84 |
|
|
|
85 |
|
|
#define NET_MAJOR 36 /* Major 36 is reserved for networking */
|
86 |
|
|
|
87 |
|
|
#ifdef __KERNEL__
|
88 |
|
|
|
89 |
|
|
struct netlink_skb_parms
|
90 |
|
|
{
|
91 |
|
|
struct ucred creds; /* Skb credentials */
|
92 |
|
|
__u32 pid;
|
93 |
|
|
__u32 groups;
|
94 |
|
|
__u32 dst_pid;
|
95 |
|
|
__u32 dst_groups;
|
96 |
|
|
kernel_cap_t eff_cap;
|
97 |
|
|
};
|
98 |
|
|
|
99 |
|
|
#define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb))
|
100 |
|
|
#define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds)
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
extern int netlink_attach(int unit, int (*function)(int,struct sk_buff *skb));
|
104 |
|
|
extern void netlink_detach(int unit);
|
105 |
|
|
extern int netlink_post(int unit, struct sk_buff *skb);
|
106 |
|
|
extern int init_netlink(void);
|
107 |
|
|
extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));
|
108 |
|
|
extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
|
109 |
|
|
extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
|
110 |
|
|
extern void netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid,
|
111 |
|
|
__u32 group, int allocation);
|
112 |
|
|
extern void netlink_set_err(struct sock *ssk, __u32 pid, __u32 group, int code);
|
113 |
|
|
extern int netlink_register_notifier(struct notifier_block *nb);
|
114 |
|
|
extern int netlink_unregister_notifier(struct notifier_block *nb);
|
115 |
|
|
|
116 |
|
|
/*
|
117 |
|
|
* skb should fit one page. This choice is good for headerless malloc.
|
118 |
|
|
*
|
119 |
|
|
* FIXME: What is the best size for SLAB???? --ANK
|
120 |
|
|
*/
|
121 |
|
|
#define NLMSG_GOODSIZE (PAGE_SIZE - ((sizeof(struct sk_buff)+0xF)&~0xF))
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
struct netlink_callback
|
125 |
|
|
{
|
126 |
|
|
struct sk_buff *skb;
|
127 |
|
|
struct nlmsghdr *nlh;
|
128 |
|
|
int (*dump)(struct sk_buff * skb, struct netlink_callback *cb);
|
129 |
|
|
int (*done)(struct netlink_callback *cb);
|
130 |
|
|
int family;
|
131 |
|
|
long args[4];
|
132 |
|
|
};
|
133 |
|
|
|
134 |
|
|
struct netlink_notify
|
135 |
|
|
{
|
136 |
|
|
int pid;
|
137 |
|
|
int protocol;
|
138 |
|
|
};
|
139 |
|
|
|
140 |
|
|
static __inline__ struct nlmsghdr *
|
141 |
|
|
__nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len)
|
142 |
|
|
{
|
143 |
|
|
struct nlmsghdr *nlh;
|
144 |
|
|
int size = NLMSG_LENGTH(len);
|
145 |
|
|
|
146 |
|
|
nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size));
|
147 |
|
|
nlh->nlmsg_type = type;
|
148 |
|
|
nlh->nlmsg_len = size;
|
149 |
|
|
nlh->nlmsg_flags = 0;
|
150 |
|
|
nlh->nlmsg_pid = pid;
|
151 |
|
|
nlh->nlmsg_seq = seq;
|
152 |
|
|
return nlh;
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
#define NLMSG_PUT(skb, pid, seq, type, len) \
|
156 |
|
|
({ if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) goto nlmsg_failure; \
|
157 |
|
|
__nlmsg_put(skb, pid, seq, type, len); })
|
158 |
|
|
|
159 |
|
|
extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
|
160 |
|
|
struct nlmsghdr *nlh,
|
161 |
|
|
int (*dump)(struct sk_buff *skb, struct netlink_callback*),
|
162 |
|
|
int (*done)(struct netlink_callback*));
|
163 |
|
|
|
164 |
|
|
#define NL_NONROOT_RECV 0x1
|
165 |
|
|
#define NL_NONROOT_SEND 0x2
|
166 |
|
|
extern void netlink_set_nonroot(int protocol, unsigned flag);
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
#endif /* __KERNEL__ */
|
170 |
|
|
|
171 |
|
|
#endif /* __LINUX_NETLINK_H */
|