Permalink
Browse files

bridge: add rtnl_link_add_bridge() function

Signed-off-by: HongweiBi <hwbi2008@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
  • Loading branch information...
HongweiBi authored and thom311 committed Jan 2, 2014
1 parent dcc0baa commit 8dabf9fb1a891400511f3c8cd2713bcb5380fb87
Showing with 29 additions and 0 deletions.
  1. +1 −0 include/netlink/route/link/bridge.h
  2. +28 −0 lib/route/link/bridge.c
@@ -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
View
@@ -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

0 comments on commit 8dabf9f

Please sign in to comment.