]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
bridge: add rtnl_link_add_bridge() function
authorHongweiBi <hwbi2008@gmail.com>
Thu, 2 Jan 2014 03:29:42 +0000 (11:29 +0800)
committerThomas Haller <thaller@redhat.com>
Tue, 14 Jan 2014 13:37:58 +0000 (14:37 +0100)
Signed-off-by: HongweiBi <hwbi2008@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
include/netlink/route/link/bridge.h
lib/route/link/bridge.c

index 74d0e6218b8e8e5dc6f2b64e84cad4538b7cd3e9..16a4505f8b74cb0450e438a2e64ef15676aa3cd8 100644 (file)
@@ -51,6 +51,7 @@ extern int    rtnl_link_bridge_get_flags(struct rtnl_link *);
 extern char * rtnl_link_bridge_flags2str(int, char *, size_t);
 extern int     rtnl_link_bridge_str2flags(const char *);
 
+extern int     rtnl_link_bridge_add(struct nl_sock *sk, const char *name);
 #ifdef __cplusplus
 }
 #endif
index fcf3272b96d2f6de31fbfdbf23b016bd89b31bd9..640b78b2c22e39ce29fb964e74c91d6bdd9f1683 100644 (file)
@@ -203,6 +203,34 @@ struct rtnl_link *rtnl_link_bridge_alloc(void)
 
        return link;
 }
+               
+/** 
+ * Create a new kernel bridge device
+ * @arg sock            netlink socket
+ * @arg name            name of the bridge device or NULL
+ *
+ * Creates a new bridge device in the kernel. If no name is
+ * provided, the kernel will automatically pick a name of the
+ * form "type%d" (e.g. bridge0, vlan1, etc.)
+ *
+ * @return 0 on success or a negative error code
+*/
+int rtnl_link_bridge_add(struct nl_sock *sk, const char *name)
+{
+       int err;
+       struct rtnl_link *link;
+
+       if (!(link = rtnl_link_bridge_alloc()))
+               return -NLE_NOMEM;
+
+       if(name)
+               rtnl_link_set_name(link, name);
+
+       err = rtnl_link_add(sk, link, NLM_F_CREATE);
+       rtnl_link_put(link);
+
+       return err;
+}
 
 /**
  * Check if a link is a bridge