Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

Links (Interfaces)
[Routing Family]


Detailed Description

Link Identification
A link can be identified by either its interface index or by its name. The kernel favours the interface index but falls back to the interface name if the interface index is lesser-than 0 for kernels >= 2.6.11. Therefore you can request changes without mapping a interface name to the corresponding index first.
Changeable Attributes
  • Link layer address
  • Link layer broadcast address
  • device mapping (ifmap) (>= 2.6.9)
  • MTU (>= 2.6.9)
  • Transmission queue length (>= 2.6.9)
  • Weight (>= 2.6.9)
  • Link name (only via access through interface index) (>= 2.6.9)
  • Flags (>= 2.6.9)
    • IFF_DEBUG
    • IFF_NOTRAILERS
    • IFF_NOARP
    • IFF_DYNAMIC
    • IFF_MULTICAST
    • IFF_PORTSEL
    • IFF_AUTOMEDIA
    • IFF_UP
    • IFF_PROMISC
    • IFF_ALLMULTI
Link Flags (linux/if.h)
   IFF_UP            Status of link (up|down)
   IFF_BROADCAST     Indicates this link allows broadcasting
   IFF_MULTICAST     Indicates this link allows multicasting
   IFF_ALLMULTI      Indicates this link is doing multicast routing
   IFF_DEBUG         Tell the driver to do debugging (currently unused)
   IFF_LOOPBACK      This is the loopback link
   IFF_POINTOPOINT   Point-to-point link
   IFF_NOARP         Link is unable to perform ARP
   IFF_PROMISC       Status of promiscious mode flag
   IFF_MASTER        Used by teql
   IFF_SLAVE         Used by teql
   IFF_PORTSEL       Indicates this link allows port selection
   IFF_AUTOMEDIA     Indicates this link selects port automatically
   IFF_DYNAMIC       Indicates the address of this link is dynamic
   IFF_RUNNING       Link is running and carrier is ok.
   IFF_NOTRAILERS    Unused, BSD compat.
Notes on IFF_PROMISC and IFF_ALLMULTI flags
Although you can query the status of IFF_PROMISC and IFF_ALLMULTI they do not represent the actual state in the kernel but rather whether the flag has been enabled/disabled by userspace. The link may be in promiscious mode even if IFF_PROMISC is not set in a link dump request response because promiscity might be needed by the driver for a period of time.
Note:
The unit of the transmission queue length depends on the link type, a common unit is packets.
1) Retrieving information about available links
 // The first step is to retrieve a list of all available interfaces within
 // the kernel and put them into a cache.
 struct nl_cache *cache = rtnl_link_alloc_cache(sk);

 // In a second step, a specific link may be looked up by either interface
 // index or interface name.
 struct rtnl_link *link = rtnl_link_get_by_name(cache, "lo");

 // rtnl_link_get_by_name() is the short version for translating the
 // interface name to an interface index first like this:
 int ifindex = rtnl_link_name2i(cache, "lo");
 struct rtnl_link *link = rtnl_link_get(cache, ifindex);

 // After successful usage, the object must be given back to the cache
 rtnl_link_put(link);
2) Changing link attributes
 // In order to change any attributes of an existing link, we must allocate
 // a new link to hold the change requests:
 struct rtnl_link *request = rtnl_link_alloc();

 // Now we can go on and specify the attributes we want to change:
 rtnl_link_set_weight(request, 300);
 rtnl_link_set_mtu(request, 1360);

 // We can also shut an interface down administratively
 rtnl_link_unset_flags(request, rtnl_link_str2flags("up"));

 // Actually, we should know which link to change, so let's look it up
 struct rtnl_link *old = rtnl_link_get(cache, "eth0");

 // Two ways exist to commit this change request, the first one is to
 // build the required netlink message and send it out in one single
 // step:
 rtnl_link_change(sk, old, request);

 // An alternative way is to build the netlink message and send it
 // out yourself using nl_send_auto_complete()
 struct nl_msg *msg = rtnl_link_build_change_request(old, request);
 nl_send_auto_complete(sk, nlmsg_hdr(msg));
 nlmsg_free(msg);

 // Don't forget to give back the link object ;->
 rtnl_link_put(old);
3) Link Type Specific Attributes
 // Some link types offer additional parameters and statistics specific
 // to their type. F.e. a VLAN link can be configured like this:
 //
 // Allocate a new link and set the info type to "vlan". This is required
 // to prepare the link to hold vlan specific attributes.
 struct rtnl_link *request = rtnl_link_alloc();
 rtnl_link_set_info_type(request, "vlan");

 // Now vlan specific attributes can be set:
 rtnl_link_vlan_set_id(request, 10);
 rtnl_link_vlan_set_ingress_map(request, 2, 8);

 // Of course the attributes can also be read, check the info type
 // to make sure you are using the right access functions:
 char *type = rtnl_link_get_info_type(link);
 if (!strcmp(type, "vlan"))
      int id = rtnl_link_vlan_get_id(link);


Modules

 Link Info API

Link Flags Translations

static struct trans_tbl link_flags []
char * rtnl_link_flags2str (int flags, char *buf, size_t len)
int rtnl_link_str2flags (const char *name)

Link Mode Translations

static struct trans_tbl link_modes []
char * rtnl_link_mode2str (int st, char *buf, size_t len)
int rtnl_link_str2mode (const char *name)

Link Operstate Translations

static struct trans_tbl link_operstates []
char * rtnl_link_operstate2str (int st, char *buf, size_t len)
int rtnl_link_str2operstate (const char *name)

Link Statistics Translations

static struct trans_tbl link_stats []
char * rtnl_link_stat2str (int st, char *buf, size_t len)
int rtnl_link_str2stat (const char *name)

Attributes

static void __assign_addr (struct rtnl_link *link, struct nl_addr **pos, struct nl_addr *new, int flag)
struct nl_addr * rtnl_link_get_addr (struct rtnl_link *link)
unsigned int rtnl_link_get_arptype (struct rtnl_link *link)
struct nl_addr * rtnl_link_get_broadcast (struct rtnl_link *link)
int rtnl_link_get_family (struct rtnl_link *link)
unsigned int rtnl_link_get_flags (struct rtnl_link *link)
int rtnl_link_get_ifindex (struct rtnl_link *link)
char * rtnl_link_get_info_type (struct rtnl_link *link)
int rtnl_link_get_link (struct rtnl_link *link)
uint8_t rtnl_link_get_linkmode (struct rtnl_link *link)
int rtnl_link_get_master (struct rtnl_link *link)
unsigned int rtnl_link_get_mtu (struct rtnl_link *link)
char * rtnl_link_get_name (struct rtnl_link *link)
uint8_t rtnl_link_get_operstate (struct rtnl_link *link)
char * rtnl_link_get_qdisc (struct rtnl_link *link)
uint64_t rtnl_link_get_stat (struct rtnl_link *link, int id)
unsigned int rtnl_link_get_txqlen (struct rtnl_link *link)
unsigned int rtnl_link_get_weight (struct rtnl_link *link)
void rtnl_link_set_addr (struct rtnl_link *link, struct nl_addr *addr)
void rtnl_link_set_arptype (struct rtnl_link *link, unsigned int arptype)
void rtnl_link_set_broadcast (struct rtnl_link *link, struct nl_addr *brd)
void rtnl_link_set_family (struct rtnl_link *link, int family)
void rtnl_link_set_flags (struct rtnl_link *link, unsigned int flags)
void rtnl_link_set_ifindex (struct rtnl_link *link, int ifindex)
int rtnl_link_set_info_type (struct rtnl_link *link, const char *type)
void rtnl_link_set_link (struct rtnl_link *link, int ifindex)
void rtnl_link_set_linkmode (struct rtnl_link *link, uint8_t linkmode)
void rtnl_link_set_master (struct rtnl_link *link, int ifindex)
void rtnl_link_set_mtu (struct rtnl_link *link, unsigned int mtu)
void rtnl_link_set_name (struct rtnl_link *link, const char *name)
void rtnl_link_set_operstate (struct rtnl_link *link, uint8_t operstate)
void rtnl_link_set_qdisc (struct rtnl_link *link, const char *qdisc)
void rtnl_link_set_txqlen (struct rtnl_link *link, unsigned int txqlen)
void rtnl_link_set_weight (struct rtnl_link *link, unsigned int weight)
void rtnl_link_unset_flags (struct rtnl_link *link, unsigned int flags)

Allocation/Freeing

struct rtnl_link * rtnl_link_alloc (void)
void rtnl_link_put (struct rtnl_link *link)

Cache Management

int rtnl_link_alloc_cache (struct nl_sock *sk, struct nl_cache **result)
struct rtnl_link * rtnl_link_get (struct nl_cache *cache, int ifindex)
struct rtnl_link * rtnl_link_get_by_name (struct nl_cache *cache, const char *name)

Link Modifications

int rtnl_link_build_change_request (struct rtnl_link *old, struct rtnl_link *tmpl, int flags, struct nl_msg **result)
int rtnl_link_change (struct nl_sock *sk, struct rtnl_link *old, struct rtnl_link *tmpl, int flags)

Name <-> Index Translations

char * rtnl_link_i2name (struct nl_cache *cache, int ifindex, char *dst, size_t len)
int rtnl_link_name2i (struct nl_cache *cache, const char *name)

Functions

static char * link_attrs2str (int attrs, char *buf, size_t len)
static int link_clone (struct nl_object *_dst, struct nl_object *_src)
static int link_compare (struct nl_object *_a, struct nl_object *_b, uint32_t attrs, int flags)
static void link_dump_details (struct nl_object *obj, struct nl_dump_params *p)
static void link_dump_env (struct nl_object *obj, struct nl_dump_params *p)
static void link_dump_line (struct nl_object *obj, struct nl_dump_params *p)
static void link_dump_stats (struct nl_object *obj, struct nl_dump_params *p)
static void __exit link_exit (void)
static void link_free_data (struct nl_object *c)
static void __init link_init (void)
static int link_msg_parser (struct nl_cache_ops *ops, struct sockaddr_nl *who, struct nlmsghdr *n, struct nl_parser_param *pp)
static int link_request_update (struct nl_cache *cache, struct nl_sock *sk)
static void release_link_info (struct rtnl_link *link)

Variables

static struct trans_tbl link_attrs []
static struct nl_af_group link_groups []
static struct nla_policy link_info_policy [IFLA_INFO_MAX+1]
static struct nl_object_ops link_obj_ops
static struct nla_policy link_policy [IFLA_MAX+1]
static struct nl_cache_ops rtnl_link_ops


Generated by  Doxygen 1.6.0   Back to index