Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

netlink.h

Go to the documentation of this file.
00001 #ifndef __LINUX_NETLINK_H
00002 #define __LINUX_NETLINK_H
00003 
00004 #define NETLINK_ROUTE           0       /* Routing/device hook                          */
00005 #define NETLINK_SKIP            1       /* Reserved for ENskip                          */
00006 #define NETLINK_USERSOCK        2       /* Reserved for user mode socket protocols      */
00007 #define NETLINK_FIREWALL        3       /* Firewalling hook                             */
00008 #define NETLINK_ARPD            8
00009 #define NETLINK_ROUTE6          11      /* af_inet6 route comm channel */
00010 #define NETLINK_IP6_FW          13
00011 #define NETLINK_TAPBASE         16      /* 16 to 31 are ethertap */
00012 
00013 #define MAX_LINKS 32            
00014 
00015 struct sockaddr_nl
00016 {
00017         sa_family_t     nl_family;      /* AF_NETLINK   */
00018         unsigned short  nl_pad;         /* zero         */
00019         __u32           nl_pid;         /* process pid  */
00020         __u32           nl_groups;      /* multicast groups mask */
00021 };
00022 
00023 struct nlmsghdr
00024 {
00025         __u32           nlmsg_len;      /* Length of message including header */
00026         __u16           nlmsg_type;     /* Message content */
00027         __u16           nlmsg_flags;    /* Additional flags */
00028         __u32           nlmsg_seq;      /* Sequence number */
00029         __u32           nlmsg_pid;      /* Sending process PID */
00030 };
00031 
00032 /* Flags values */
00033 
00034 #define NLM_F_REQUEST           1       /* It is request message.       */
00035 #define NLM_F_MULTI             2       /* Multipart message, terminated by NLMSG_DONE */
00036 #define NLM_F_ACK               4       /* Reply with ack, with zero or error code */
00037 #define NLM_F_ECHO              8       /* Echo this request            */
00038 
00039 /* Modifiers to GET request */
00040 #define NLM_F_ROOT      0x100   /* specify tree root    */
00041 #define NLM_F_MATCH     0x200   /* return all matching  */
00042 #define NLM_F_ATOMIC    0x400   /* atomic GET           */
00043 #define NLM_F_DUMP      (NLM_F_ROOT|NLM_F_MATCH)
00044 
00045 /* Modifiers to NEW request */
00046 #define NLM_F_REPLACE   0x100   /* Override existing            */
00047 #define NLM_F_EXCL      0x200   /* Do not touch, if it exists   */
00048 #define NLM_F_CREATE    0x400   /* Create, if it does not exist */
00049 #define NLM_F_APPEND    0x800   /* Add to end of list           */
00050 
00051 /*
00052    4.4BSD ADD           NLM_F_CREATE|NLM_F_EXCL
00053    4.4BSD CHANGE        NLM_F_REPLACE
00054 
00055    True CHANGE          NLM_F_CREATE|NLM_F_REPLACE
00056    Append               NLM_F_CREATE
00057    Check                NLM_F_EXCL
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     /* Nothing.             */
00072 #define NLMSG_ERROR             0x2     /* Error                */
00073 #define NLMSG_DONE              0x3     /* End of a dump        */
00074 #define NLMSG_OVERRUN           0x4     /* Data lost            */
00075 
00076 struct nlmsgerr
00077 {
00078         int             error;
00079         struct nlmsghdr msg;
00080 };
00081 
00082 #define NET_MAJOR 36            /* Major 36 is reserved for networking                                          */
00083 
00084 #ifdef __KERNEL__
00085 
00086 struct netlink_skb_parms
00087 {
00088         struct ucred            creds;          /* Skb credentials      */
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  *      skb should fit one page. This choice is good for headerless malloc.
00113  *
00114  *      FIXME: What is the best size for SLAB???? --ANK
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 /* __KERNEL__ */
00157 
00158 #endif  /* __LINUX_NETLINK_H */