]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add utility u16 get/put
authorJamal Hadi Salim <hadi@cyberus.ca>
Tue, 15 Dec 2009 09:14:26 +0000 (10:14 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 15 Dec 2009 09:14:26 +0000 (10:14 +0100)
Add utility functions to parse a u16 and put a u16 on a
netlink message

Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/nl.c
src/lxc/nl.h
src/lxc/utils.c
src/lxc/utils.h

index 261ffb5276c3697cf605ac41c319275b6d682bed..b5d3dd0f46b6bf0e68249f61d2904c7f2a11e85f 100644 (file)
@@ -78,6 +78,11 @@ extern int nla_put_u32(struct nlmsg *nlmsg, int attr, int value)
        return nla_put(nlmsg, attr, &value, sizeof(value));
 }
 
+extern int nla_put_u16(struct nlmsg *nlmsg, int attr, ushort value)
+{
+       return nla_put(nlmsg, attr, &value, 2);
+}
+
 extern int nla_put_attr(struct nlmsg *nlmsg, int attr)
 {
        return nla_put(nlmsg, attr, NULL, 0);
@@ -184,6 +189,9 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
        return ret;
 }
 
+#ifndef NLMSG_ERROR
+#define NLMSG_ERROR                0x2
+#endif
 extern int netlink_transaction(struct nl_handler *handler, 
                               struct nlmsg *request, struct nlmsg *answer)
 {
@@ -201,6 +209,8 @@ extern int netlink_transaction(struct nl_handler *handler,
        if (answer->nlmsghdr.nlmsg_type == NLMSG_ERROR) {
                struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(answer);
                errno = -err->error;
+               if (errno)
+                       perror("Error configuring kernel");
                return -errno;
        }
        
index 2f760de2c08d3afc5ebe504ffeaba4d7c400b4a8..864780a5ad4fd4ae5eafbd76de75dd7f24141568 100644 (file)
@@ -160,6 +160,17 @@ int nla_put_buffer(struct nlmsg *nlmsg, int attr,
  */
 int nla_put_u32(struct nlmsg *nlmsg, int attr, int value);
 
+/*
+ * nla_put_u16: copy an integer to a netlink message attribute
+ *
+ * @nlmsg: the netlink message to be filled
+ * @attr: the attribute name of the unsigned 16-bit value
+ * @value: 16-bit attribute data value to be copied to the netlink message
+ *
+ * Returns 0 on success, < 0 otherwise
+ */
+int nla_put_u16(struct nlmsg *nlmsg, int attr, ushort value);
+
 /*
  * nla_put_attr: add an attribute name to a netlink 
  *
index f9477a34780687311d3c39cce1d5b860de72b49d..1869c0cb7692d01d208c47f1bb785c4e462b5703 100644 (file)
@@ -270,3 +270,22 @@ extern int lxc_setup_fs(void)
 
        return 0;
 }
+
+/* borrowed from iproute2 */
+extern int get_u16(ushort *val, const char *arg, int base)
+{
+       unsigned long res;
+       char *ptr;
+
+       if (!arg || !*arg)
+               return -1;
+
+       res = strtoul(arg, &ptr, base);
+       if (!ptr || ptr == arg || *ptr || res > 0xFFFF)
+               return -1;
+
+       *val = res;
+
+       return 0;
+}
+
index cb4e6a0bbcbc775825a2c4244056b5680861d7af..c49c4ffa5cbef7ec1f728164448afcd562b8a431 100644 (file)
@@ -54,3 +54,4 @@ extern int lxc_copy_file(const char *src, const char *dst);
 extern int lxc_close_inherited_fd(int fd);
 extern int lxc_close_all_inherited_fd(void);
 extern int lxc_setup_fs(void);
+extern int get_u16(ushort *val, const char *arg, int base);