[lldp-devel] [PATCH 3/3] lldp_rtnl remove mynla_xxx functions.

Thomas Richter tmricht at linux.vnet.ibm.com
Thu Nov 21 09:26:41 UTC 2013


Remove the mynla_xxx functions and use the libnl library
provided ones.

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 include/lldp_rtnl.h |  23 ---------
 lldp_rtnl.c         | 132 ----------------------------------------------------
 2 files changed, 155 deletions(-)

diff --git a/include/lldp_rtnl.h b/include/lldp_rtnl.h
index 2bb09b1..ed65d9c 100644
--- a/include/lldp_rtnl.h
+++ b/include/lldp_rtnl.h
@@ -33,29 +33,6 @@
 
 #include "include/linux/netlink.h"
 
-/*
- * Helper functions to construct a netlink message.
- */
-void mynla_nest_end(struct nlmsghdr *, struct nlattr *);
-struct nlattr *mynla_nest_start(struct nlmsghdr *, int);
-void mynla_put(struct nlmsghdr *, int, size_t, void *);
-void mynla_put_u8(struct nlmsghdr *, int, __u8);
-void mynla_put_u16(struct nlmsghdr *, int, __u16);
-void mynla_put_u32(struct nlmsghdr *, int, __u32);
-void mynla_put_s32(struct nlmsghdr *nlh, int type, __s32);
-__u8 mynla_get_u8(const struct nlattr *);
-__u16 mynla_get_u16(const struct nlattr *);
-__u32 mynla_get_u32(const struct nlattr *);
-__s32 mynla_get_s32(const struct nlattr *);
-void mynla_get(const struct nlattr *, size_t, void *);
-void *mynla_data(const struct nlattr *);
-int mynla_payload(const struct nlattr *);
-int mynla_type(const struct nlattr *);
-int mynla_ok(const struct nlattr *, int);
-int mynla_total_size(int);
-struct nlattr *mynla_next(const struct nlattr *, int *);
-int mynla_parse(struct nlattr **, size_t, struct nlattr *, int);
-
 int get_operstate(char *ifname);
 int set_operstate(char *ifname, __u8 operstate);
 int set_linkmode(int ifindex, const char *ifname, __u8 linkmode);
diff --git a/lldp_rtnl.c b/lldp_rtnl.c
index dffc0ba..33b4d19 100644
--- a/lldp_rtnl.c
+++ b/lldp_rtnl.c
@@ -46,138 +46,6 @@
 
 #define NLMSG_SIZE 1024
 
-/*
- * Helper functions to construct a netlink message.
- * The functions assume the nlmsghdr.nlmsg_len is set correctly.
- */
-void mynla_nest_end(struct nlmsghdr *nlh, struct nlattr *start)
-{
-	start->nla_type |= NLA_F_NESTED;
-	start->nla_len = (void *)nlh + nlh->nlmsg_len - (void *)start;
-}
-
-struct nlattr *mynla_nest_start(struct nlmsghdr *nlh, int type)
-{
-	struct nlattr *ap = (struct nlattr *)((void *)nlh + nlh->nlmsg_len);
-
-	ap->nla_type = type;
-	nlh->nlmsg_len += NLA_HDRLEN;
-	return ap;
-}
-
-void mynla_put(struct nlmsghdr *nlh, int type, size_t len, void *data)
-{
-	struct nlattr *ap = (struct nlattr *)((void *)nlh + nlh->nlmsg_len);
-
-	ap->nla_type = type;
-	ap->nla_len = NLA_HDRLEN + len;
-	memcpy(ap + 1, data, len);
-	nlh->nlmsg_len += NLA_HDRLEN + NLA_ALIGN(len);
-}
-
-void mynla_put_u8(struct nlmsghdr *nlh, int type, __u8 data)
-{
-	mynla_put(nlh, type, sizeof data, &data);
-}
-
-void mynla_put_u16(struct nlmsghdr *nlh, int type, __u16 data)
-{
-	mynla_put(nlh, type, sizeof data, &data);
-}
-
-void mynla_put_u32(struct nlmsghdr *nlh, int type, __u32 data)
-{
-	mynla_put(nlh, type, sizeof data, &data);
-}
-
-void mynla_put_s32(struct nlmsghdr *nlh, int type, __s32 data)
-{
-	mynla_put(nlh, type, sizeof data, &data);
-}
-
-void mynla_get(const struct nlattr *nla, size_t len, void *data)
-{
-	memcpy(data, mynla_data(nla), len);
-}
-
-__s32 mynla_get_s32(const struct nlattr *nla)
-{
-	return *(__u32 *)mynla_data(nla);
-}
-
-__u32 mynla_get_u32(const struct nlattr *nla)
-{
-	return *(__u32 *)mynla_data(nla);
-}
-
-__u16 mynla_get_u16(const struct nlattr *nla)
-{
-	return *(__u16 *)mynla_data(nla);
-}
-
-__u8 mynla_get_u8(const struct nlattr *nla)
-{
-	return *(__u8 *)mynla_data(nla);
-}
-
-void *mynla_data(const struct nlattr *nla)
-{
-	return (char *)nla + NLA_HDRLEN;
-}
-
-int mynla_payload(const struct nlattr *nla)
-{
-	return nla->nla_len - NLA_HDRLEN;
-}
-
-int mynla_type(const struct nlattr *nla)
-{
-	return nla->nla_type & ~NLA_F_NESTED;
-}
-
-int mynla_ok(const struct nlattr *nla, int rest)
-{
-	return rest >= (int) sizeof(*nla) &&
-	       nla->nla_len >= sizeof(*nla) && nla->nla_len <= rest;
-}
-
-struct nlattr *mynla_next(const struct nlattr *nla, int *rest)
-{
-	int len = NLA_ALIGN(nla->nla_len);
-
-	*rest -= len;
-	return (struct nlattr *)((char *)nla + len);
-}
-
-static inline int mynla_attr_size(int payload)
-{
-	return NLA_HDRLEN + payload;
-}
-
-int mynla_total_size(int payload)
-{
-	return NLA_ALIGN(mynla_attr_size(payload));
-}
-
-/*
- * Parse a list of netlink attributes.
- * Return 0 on success and errno when the parsing fails.
- */
-int mynla_parse(struct nlattr **tb, size_t tb_len, struct nlattr *pos,
-		int attrlen)
-{
-	unsigned short nla_type;
-
-	while (mynla_ok(pos, attrlen)) {
-		nla_type = mynla_type(pos);
-		if (nla_type < tb_len)
-			tb[nla_type] = (struct nlattr *)pos;
-		pos = mynla_next(pos, &attrlen);
-	}
-	return (attrlen) ? -EINVAL : 0;
-}
-
-
 typedef int rtnl_handler(struct nlmsghdr *nh, void *arg);
 
 /**
-- 
1.8.3.1



More information about the lldp-devel mailing list