00001 #ifndef __LINUX_NETLINK_H
00002 #define __LINUX_NETLINK_H
00003
00004 #define NETLINK_ROUTE 0
00005 #define NETLINK_SKIP 1
00006 #define NETLINK_USERSOCK 2
00007 #define NETLINK_FIREWALL 3
00008 #define NETLINK_ARPD 8
00009 #define NETLINK_ROUTE6 11
00010 #define NETLINK_IP6_FW 13
00011 #define NETLINK_TAPBASE 16
00012
00013 #define MAX_LINKS 32
00014
00015 struct sockaddr_nl
00016 {
00017 sa_family_t nl_family;
00018 unsigned short nl_pad;
00019 __u32 nl_pid;
00020 __u32 nl_groups;
00021 };
00022
00023 struct nlmsghdr
00024 {
00025 __u32 nlmsg_len;
00026 __u16 nlmsg_type;
00027 __u16 nlmsg_flags;
00028 __u32 nlmsg_seq;
00029 __u32 nlmsg_pid;
00030 };
00031
00032
00033
00034 #define NLM_F_REQUEST 1
00035 #define NLM_F_MULTI 2
00036 #define NLM_F_ACK 4
00037 #define NLM_F_ECHO 8
00038
00039
00040 #define NLM_F_ROOT 0x100
00041 #define NLM_F_MATCH 0x200
00042 #define NLM_F_ATOMIC 0x400
00043 #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
00044
00045
00046 #define NLM_F_REPLACE 0x100
00047 #define NLM_F_EXCL 0x200
00048 #define NLM_F_CREATE 0x400
00049 #define NLM_F_APPEND 0x800
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #define NLMSG_ALIGNTO 4
00061 #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
00062 #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr)))
00063 #define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
00064 #define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
00065 #define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
00066 (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
00067 #define NLMSG_OK(nlh,len) ((len) > 0 && (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
00068 (nlh)->nlmsg_len <= (len))
00069 #define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
00070
00071 #define NLMSG_NOOP 0x1
00072 #define NLMSG_ERROR 0x2
00073 #define NLMSG_DONE 0x3
00074 #define NLMSG_OVERRUN 0x4
00075
00076 struct nlmsgerr
00077 {
00078 int error;
00079 struct nlmsghdr msg;
00080 };
00081
00082 #define NET_MAJOR 36
00083
00084 #ifdef __KERNEL__
00085
00086 struct netlink_skb_parms
00087 {
00088 struct ucred creds;
00089 __u32 pid;
00090 __u32 groups;
00091 __u32 dst_pid;
00092 __u32 dst_groups;
00093 kernel_cap_t eff_cap;
00094 };
00095
00096 #define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb))
00097 #define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds)
00098
00099
00100 extern int netlink_attach(int unit, int (*function)(int,struct sk_buff *skb));
00101 extern void netlink_detach(int unit);
00102 extern int netlink_post(int unit, struct sk_buff *skb);
00103 extern int init_netlink(void);
00104 extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));
00105 extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
00106 extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
00107 extern void netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid,
00108 __u32 group, int allocation);
00109 extern void netlink_set_err(struct sock *ssk, __u32 pid, __u32 group, int code);
00110
00111
00112
00113
00114
00115
00116 #define NLMSG_GOODSIZE (PAGE_SIZE - ((sizeof(struct sk_buff)+0xF)&~0xF))
00117
00118
00119 struct netlink_callback
00120 {
00121 struct sk_buff *skb;
00122 struct nlmsghdr *nlh;
00123 int (*dump)(struct sk_buff * skb, struct netlink_callback *cb);
00124 int (*done)(struct netlink_callback *cb);
00125 int family;
00126 long args[4];
00127 };
00128
00129 extern __inline__ struct nlmsghdr *
00130 __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len)
00131 {
00132 struct nlmsghdr *nlh;
00133 int size = NLMSG_LENGTH(len);
00134
00135 nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size));
00136 nlh->nlmsg_type = type;
00137 nlh->nlmsg_len = size;
00138 nlh->nlmsg_flags = 0;
00139 nlh->nlmsg_pid = pid;
00140 nlh->nlmsg_seq = seq;
00141 return nlh;
00142 }
00143
00144 #define NLMSG_PUT(skb, pid, seq, type, len) \
00145 ({ if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) goto nlmsg_failure; \
00146 __nlmsg_put(skb, pid, seq, type, len); })
00147
00148 extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
00149 struct nlmsghdr *nlh,
00150 int (*dump)(struct sk_buff *skb, struct netlink_callback*),
00151 int (*done)(struct netlink_callback*));
00152
00153
00154 extern void netlink_proto_init(struct net_proto *pro);
00155
00156 #endif
00157
00158 #endif