vlan: Provide rtnl_link_vlan_alloc()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
parent
bb9911b5a3
commit
ee4122a12e
4 changed files with 28 additions and 13 deletions
|
@ -693,15 +693,12 @@ int master_index;
|
|||
if (!(master_index = rtnl_link_name2i(link_cache, "eth0")))
|
||||
/* error */
|
||||
|
||||
/* allocate new link object to configure the vlan device */
|
||||
link = rtnl_link_alloc();
|
||||
/* allocate new link object of type vlan */
|
||||
link = rtnl_link_vlan_alloc();
|
||||
|
||||
/* set eth0 to be our master device */
|
||||
rtnl_link_set_link(link, master_index);
|
||||
|
||||
if ((err = rtnl_link_set_type(link, "vlan")) < 0)
|
||||
/* error */
|
||||
|
||||
rtnl_link_vlan_set_id(link, 10);
|
||||
|
||||
if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
#ifndef NETLINK_LINK_VLAN_H_
|
||||
|
@ -27,6 +27,8 @@ struct vlan_map
|
|||
|
||||
#define VLAN_PRIO_MAX 7
|
||||
|
||||
extern struct rtnl_link *rtnl_link_vlan_alloc(void);
|
||||
|
||||
extern int rtnl_link_is_vlan(struct rtnl_link *);
|
||||
|
||||
extern char * rtnl_link_vlan_flags2str(int, char *, size_t);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* Copyright (c) 2003-2010 Thomas Graf <tgraf@suug.ch>
|
||||
* Copyright (c) 2003-2013 Thomas Graf <tgraf@suug.ch>
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -340,6 +340,27 @@ static struct rtnl_link_info_ops vlan_info_ops = {
|
|||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate link object of type VLAN
|
||||
*
|
||||
* @return Allocated link object or NULL.
|
||||
*/
|
||||
struct rtnl_link *rtnl_link_vlan_alloc(void)
|
||||
{
|
||||
struct rtnl_link *link;
|
||||
int err;
|
||||
|
||||
if (!(link = rtnl_link_alloc()))
|
||||
return NULL;
|
||||
|
||||
if ((err = rtnl_link_set_type(link, "vlan")) < 0) {
|
||||
rtnl_link_put(link);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if link is a VLAN link
|
||||
* @arg link Link object
|
||||
|
|
|
@ -25,15 +25,10 @@ int main(int argc, char *argv[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
link = rtnl_link_alloc();
|
||||
link = rtnl_link_vlan_alloc();
|
||||
|
||||
rtnl_link_set_link(link, master_index);
|
||||
|
||||
if ((err = rtnl_link_set_type(link, "vlan")) < 0) {
|
||||
nl_perror(err, "Unable to set link info type");
|
||||
return err;
|
||||
}
|
||||
|
||||
rtnl_link_vlan_set_id(link, 10);
|
||||
|
||||
if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue