libnl 2.0
|
00001 /* 00002 * netlink/msg.c Netlink Messages Interface 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 #ifndef NETLINK_MSG_H_ 00013 #define NETLINK_MSG_H_ 00014 00015 #include <netlink/netlink.h> 00016 #include <netlink/object.h> 00017 #include <netlink/attr.h> 00018 00019 #ifdef __cplusplus 00020 extern "C" { 00021 #endif 00022 00023 #define NL_DONTPAD 0 00024 00025 /** 00026 * @ingroup msg 00027 * @brief 00028 * Will cause the netlink pid to be set to the pid assigned to 00029 * the netlink handle (socket) just before sending the message off. 00030 * @note Requires the use of nl_send_auto_complete()! 00031 */ 00032 #define NL_AUTO_PID 0 00033 00034 /** 00035 * @ingroup msg 00036 * @brief 00037 * May be used to refer to a sequence number which should be 00038 * automatically set just before sending the message off. 00039 * @note Requires the use of nl_send_auto_complete()! 00040 */ 00041 #define NL_AUTO_SEQ 0 00042 00043 struct nl_msg; 00044 struct nl_tree; 00045 struct ucred; 00046 00047 /* size calculations */ 00048 extern int nlmsg_msg_size(int); 00049 extern int nlmsg_total_size(int); 00050 extern int nlmsg_padlen(int); 00051 00052 /* payload access */ 00053 extern void * nlmsg_data(const struct nlmsghdr *); 00054 extern int nlmsg_len(const struct nlmsghdr *); 00055 extern void * nlmsg_tail(const struct nlmsghdr *); 00056 00057 /* attribute access */ 00058 extern struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int); 00059 extern int nlmsg_attrlen(const struct nlmsghdr *, int); 00060 00061 /* message parsing */ 00062 extern int nlmsg_valid_hdr(const struct nlmsghdr *, int); 00063 extern int nlmsg_ok(const struct nlmsghdr *, int); 00064 extern struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *); 00065 extern int nlmsg_parse(struct nlmsghdr *, int, struct nlattr **, 00066 int, struct nla_policy *); 00067 extern struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int); 00068 extern int nlmsg_validate(struct nlmsghdr *, int, int, 00069 struct nla_policy *); 00070 00071 extern struct nl_msg * nlmsg_alloc(void); 00072 extern struct nl_msg * nlmsg_alloc_size(size_t); 00073 extern struct nl_msg * nlmsg_alloc_simple(int, int); 00074 extern void nlmsg_set_default_size(size_t); 00075 extern struct nl_msg * nlmsg_inherit(struct nlmsghdr *); 00076 extern struct nl_msg * nlmsg_convert(struct nlmsghdr *); 00077 extern void * nlmsg_reserve(struct nl_msg *, size_t, int); 00078 extern int nlmsg_append(struct nl_msg *, void *, size_t, int); 00079 extern int nlmsg_expand(struct nl_msg *, size_t); 00080 00081 extern struct nlmsghdr * nlmsg_put(struct nl_msg *, uint32_t, uint32_t, 00082 int, int, int); 00083 extern struct nlmsghdr * nlmsg_hdr(struct nl_msg *); 00084 extern void nlmsg_get(struct nl_msg *); 00085 extern void nlmsg_free(struct nl_msg *); 00086 00087 /* attribute modification */ 00088 extern void nlmsg_set_proto(struct nl_msg *, int); 00089 extern int nlmsg_get_proto(struct nl_msg *); 00090 extern size_t nlmsg_get_max_size(struct nl_msg *); 00091 extern void nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *); 00092 extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *); 00093 extern void nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *); 00094 extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *); 00095 extern void nlmsg_set_creds(struct nl_msg *, struct ucred *); 00096 extern struct ucred * nlmsg_get_creds(struct nl_msg *); 00097 00098 extern char * nl_nlmsgtype2str(int, char *, size_t); 00099 extern int nl_str2nlmsgtype(const char *); 00100 00101 extern char * nl_nlmsg_flags2str(int, char *, size_t); 00102 00103 extern int nl_msg_parse(struct nl_msg *, 00104 void (*cb)(struct nl_object *, void *), 00105 void *); 00106 00107 extern void nl_msg_dump(struct nl_msg *, FILE *); 00108 00109 /** 00110 * @name Iterators 00111 * @{ 00112 */ 00113 00114 /** 00115 * @ingroup msg 00116 * Iterate over a stream of attributes in a message 00117 * @arg pos loop counter, set to current attribute 00118 * @arg nlh netlink message header 00119 * @arg hdrlen length of family header 00120 * @arg rem initialized to len, holds bytes currently remaining in stream 00121 */ 00122 #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \ 00123 nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \ 00124 nlmsg_attrlen(nlh, hdrlen), rem) 00125 00126 /** 00127 * Iterate over a stream of messages 00128 * @arg pos loop counter, set to current message 00129 * @arg head head of message stream 00130 * @arg len length of message stream 00131 * @arg rem initialized to len, holds bytes currently remaining in stream 00132 */ 00133 #define nlmsg_for_each_msg(pos, head, len, rem) \ 00134 for (pos = head, rem = len; \ 00135 nlmsg_ok(pos, rem); \ 00136 pos = nlmsg_next(pos, &(rem))) 00137 00138 /** @} */ 00139 00140 #ifdef __cplusplus 00141 } 00142 #endif 00143 00144 #endif