libnl 3.0
|
00001 struct nl_msg *build_msg(int ifindex, struct nl_addr *lladdr, int mtu) 00002 { 00003 struct nl_msg *msg; 00004 struct nlattr *info, *vlan; 00005 struct ifinfomsg ifi = { 00006 .ifi_family = AF_INET, 00007 .ifi_index = ifindex, 00008 }; 00009 00010 /* Allocate a default sized netlink message */ 00011 if (!(msg = nlmsg_alloc_simple(RTM_SETLINK, 0))) 00012 return NULL; 00013 00014 /* Append the protocol specific header (struct ifinfomsg)*/ 00015 if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0) 00016 goto nla_put_failure 00017 00018 /* Append a 32 bit integer attribute to carry the MTU */ 00019 NLA_PUT_U32(msg, IFLA_MTU, mtu); 00020 00021 /* Append a unspecific attribute to carry the link layer address */ 00022 NLA_PUT_ADDR(msg, IFLA_ADDRESS, lladdr); 00023 00024 /* Append a container for nested attributes to carry link information */ 00025 if (!(info = nla_nest_start(msg, IFLA_LINKINFO))) 00026 goto nla_put_failure; 00027 00028 /* Put a string attribute into the container */ 00029 NLA_PUT_STRING(msg, IFLA_INFO_KIND, "vlan"); 00030 00031 /* 00032 * Append another container inside the open container to carry 00033 * vlan specific attributes 00034 */ 00035 if (!(vlan = nla_nest_start(msg, IFLA_INFO_DATA))) 00036 goto nla_put_failure; 00037 00038 /* add vlan specific info attributes here... */ 00039 00040 /* Finish nesting the vlan attributes and close the second container. */ 00041 nla_nest_end(msg, vlan); 00042 00043 /* Finish nesting the link info attribute and close the first container. */ 00044 nla_nest_end(msg, info); 00045 00046 return msg; 00047 00048 nla_put_failure: 00049 nlmsg_free(msg); 00050 return NULL; 00051 }