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

struct nl_msg* rtnl_link_build_change_request ( struct rtnl_link *  old,
struct rtnl_link *  tmpl,
int  flags 
) [read]

Builds a netlink change request message to change link attributes

  • old link to be changed
  • tmpl template with requested changes
  • flags additional netlink message flags
Builds a new netlink message requesting a change of link attributes. The netlink message header isn't fully equipped with all relevant fields and must be sent out via nl_send_auto_complete() or supplemented as needed. old must point to a link currently configured in the kernel and tmpl must contain the attributes to be changed set via rtnl_link_set_* functions.

New netlink message
Not all attributes can be changed, see Changeable Attributes for more details.

Definition at line 744 of file link.c.

References NLA_PUT_ADDR, NLA_PUT_STRING, NLA_PUT_U32, nlmsg_append(), and nlmsg_free().

Referenced by rtnl_link_change().

      struct nl_msg *msg;
      struct ifinfomsg ifi = {
            .ifi_family = old->l_family,
            .ifi_index = old->l_index,

      if (tmpl->l_mask & LINK_ATTR_FLAGS) {
            ifi.ifi_flags = old->l_flags & ~tmpl->l_flag_mask;
            ifi.ifi_flags |= tmpl->l_flags;

      msg = nlmsg_build_simple(RTM_SETLINK, flags);
      if (!msg)
            goto nla_put_failure;

      if (nlmsg_append(msg, &ifi, sizeof(ifi), 1) < 0)
            goto nla_put_failure;

      if (tmpl->l_mask & LINK_ATTR_ADDR)
            NLA_PUT_ADDR(msg, IFLA_ADDRESS, tmpl->l_addr);

      if (tmpl->l_mask & LINK_ATTR_BRD)
            NLA_PUT_ADDR(msg, IFLA_BROADCAST, tmpl->l_bcast);

      if (tmpl->l_mask & LINK_ATTR_MTU)
            NLA_PUT_U32(msg, IFLA_MTU, tmpl->l_mtu);

      if (tmpl->l_mask & LINK_ATTR_TXQLEN)
            NLA_PUT_U32(msg, IFLA_TXQLEN, tmpl->l_txqlen);

      if (tmpl->l_mask & LINK_ATTR_WEIGHT)
            NLA_PUT_U32(msg, IFLA_WEIGHT, tmpl->l_weight);

      if (tmpl->l_mask & LINK_ATTR_IFNAME)
            NLA_PUT_STRING(msg, IFLA_IFNAME, tmpl->l_name);

      return msg;

      return NULL;

Generated by  Doxygen 1.6.0   Back to index