From 8dabf9fb1a891400511f3c8cd2713bcb5380fb87 Mon Sep 17 00:00:00 2001 From: HongweiBi Date: Thu, 2 Jan 2014 11:29:42 +0800 Subject: [PATCH] bridge: add rtnl_link_add_bridge() function Signed-off-by: HongweiBi Signed-off-by: Thomas Haller --- include/netlink/route/link/bridge.h | 1 + lib/route/link/bridge.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/netlink/route/link/bridge.h b/include/netlink/route/link/bridge.h index 74d0e62..16a4505 100644 --- a/include/netlink/route/link/bridge.h +++ b/include/netlink/route/link/bridge.h @@ -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 diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c index fcf3272..640b78b 100644 --- a/lib/route/link/bridge.c +++ b/lib/route/link/bridge.c @@ -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 -- 2.40.0