libnl 1.1
|
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 /* Backward compatibility */ 00072 #define nlmsg_new() nlmsg_alloc() 00073 #define nlmsg_build_simple(a, b) nlmsg_alloc_simple(a, b) 00074 #define nlmsg_build(ptr) nlmsg_inherit(ptr) 00075 00076 extern struct nl_msg * nlmsg_alloc(void); 00077 extern struct nl_msg * nlmsg_alloc_size(size_t); 00078 extern struct nl_msg * nlmsg_alloc_simple(int, int); 00079 extern void nlmsg_set_default_size(size_t); 00080 extern struct nl_msg * nlmsg_inherit(struct nlmsghdr *); 00081 extern struct nl_msg * nlmsg_convert(struct nlmsghdr *); 00082 extern void * nlmsg_reserve(struct nl_msg *, size_t, int); 00083 extern int nlmsg_append(struct nl_msg *, void *, size_t, int); 00084 extern int nlmsg_expand(struct nl_msg *, size_t); 00085 00086 extern struct nlmsghdr * nlmsg_put(struct nl_msg *, uint32_t, uint32_t, 00087 int, int, int); 00088 extern struct nlmsghdr * nlmsg_hdr(struct nl_msg *); 00089 extern void nlmsg_free(struct nl_msg *); 00090 00091 /* attribute modification */ 00092 extern void nlmsg_set_proto(struct nl_msg *, int); 00093 extern int nlmsg_get_proto(struct nl_msg *); 00094 extern size_t nlmsg_get_max_size(struct nl_msg *); 00095 extern void nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *); 00096 extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *); 00097 extern void nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *); 00098 extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *); 00099 extern void nlmsg_set_creds(struct nl_msg *, struct ucred *); 00100 extern struct ucred * nlmsg_get_creds(struct nl_msg *); 00101 00102 extern char * nl_nlmsgtype2str(int, char *, size_t); 00103 extern int nl_str2nlmsgtype(const char *); 00104 00105 extern char * nl_nlmsg_flags2str(int, char *, size_t); 00106 00107 extern int nl_msg_parse(struct nl_msg *, 00108 void (*cb)(struct nl_object *, void *), 00109 void *); 00110 00111 extern void nl_msg_dump(struct nl_msg *, FILE *); 00112 00113 /** 00114 * @name Iterators 00115 * @{ 00116 */ 00117 00118 /** 00119 * @ingroup msg 00120 * Iterate over a stream of attributes in a message 00121 * @arg pos loop counter, set to current attribute 00122 * @arg nlh netlink message header 00123 * @arg hdrlen length of family header 00124 * @arg rem initialized to len, holds bytes currently remaining in stream 00125 */ 00126 #define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \ 00127 nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \ 00128 nlmsg_attrlen(nlh, hdrlen), rem) 00129 00130 /** 00131 * Iterate over a stream of messages 00132 * @arg pos loop counter, set to current message 00133 * @arg head head of message stream 00134 * @arg len length of message stream 00135 * @arg rem initialized to len, holds bytes currently remaining in stream 00136 */ 00137 #define nlmsg_for_each_msg(pos, head, len, rem) \ 00138 for (pos = head, rem = len; \ 00139 nlmsg_ok(pos, rem); \ 00140 pos = nlmsg_next(pos, &(rem))) 00141 00142 /** @} */ 00143 00144 #ifdef __cplusplus 00145 } 00146 #endif 00147 00148 #endif