22#include <netlink-private/netlink.h>
23#include <netlink-private/route/link/api.h>
24#include <netlink/netlink.h>
25#include <netlink/route/link.h>
27#include <linux/if_ether.h>
28#include <linux/if_link.h>
29#include <netlink-private/route/link/sriov.h>
30#include <netlink/route/link/sriov.h>
37#define SET_VF_STAT(link, vf_num, stb, stat, attr) \
38 vf_data->vf_stats[stat] = nla_get_u64(stb[attr])
41#define SRIOV_ATTR_INDEX (1 << 0)
42#define SRIOV_ATTR_ADDR (1 << 1)
43#define SRIOV_ATTR_VLAN (1 << 2)
44#define SRIOV_ATTR_TX_RATE (1 << 3)
45#define SRIOV_ATTR_SPOOFCHK (1 << 4)
46#define SRIOV_ATTR_RATE_MAX (1 << 5)
47#define SRIOV_ATTR_RATE_MIN (1 << 6)
48#define SRIOV_ATTR_LINK_STATE (1 << 7)
49#define SRIOV_ATTR_RSS_QUERY_EN (1 << 8)
50#define SRIOV_ATTR_STATS (1 << 9)
51#define SRIOV_ATTR_TRUST (1 << 10)
52#define SRIOV_ATTR_IB_NODE_GUID (1 << 11)
53#define SRIOV_ATTR_IB_PORT_GUID (1 << 12)
55static struct nla_policy sriov_info_policy[IFLA_VF_MAX+1] = {
56 [IFLA_VF_MAC] = { .
minlen =
sizeof(
struct ifla_vf_mac) },
57 [IFLA_VF_VLAN] = { .minlen =
sizeof(
struct ifla_vf_vlan) },
59 [IFLA_VF_TX_RATE] = { .minlen =
sizeof(
struct ifla_vf_tx_rate) },
60 [IFLA_VF_SPOOFCHK] = { .minlen =
sizeof(
struct ifla_vf_spoofchk) },
61 [IFLA_VF_RATE] = { .minlen =
sizeof(
struct ifla_vf_rate) },
62 [IFLA_VF_LINK_STATE] = { .minlen =
sizeof(
struct ifla_vf_link_state) },
63 [IFLA_VF_RSS_QUERY_EN] = { .minlen =
sizeof(
struct ifla_vf_rss_query_en) },
65 [IFLA_VF_TRUST] = { .minlen =
sizeof(
struct ifla_vf_trust) },
66 [IFLA_VF_IB_NODE_GUID] = { .minlen =
sizeof(
struct ifla_vf_guid) },
67 [IFLA_VF_IB_PORT_GUID] = { .minlen =
sizeof(
struct ifla_vf_guid) },
70static struct nla_policy sriov_stats_policy[IFLA_VF_STATS_MAX+1] = {
72 [IFLA_VF_STATS_TX_PACKETS] = { .type =
NLA_U64 },
73 [IFLA_VF_STATS_RX_BYTES] = { .type =
NLA_U64 },
74 [IFLA_VF_STATS_TX_BYTES] = { .type =
NLA_U64 },
75 [IFLA_VF_STATS_BROADCAST] = { .type =
NLA_U64 },
76 [IFLA_VF_STATS_MULTICAST] = { .type =
NLA_U64 },
84 struct nl_addr *vf_addr;
85 struct rtnl_link_vf *s_list, *d_vf, *s_vf, *next, *dest_h = NULL;
89 if (!rtnl_link_has_vf_list(src))
95 dest_h = dst->l_vf_list;
96 s_list = src->l_vf_list;
98 nl_list_for_each_entry_safe(s_vf, next, &s_list->vf_list, vf_list) {
102 memcpy(d_vf, s_vf,
sizeof(*s_vf));
104 if (s_vf->ce_mask & SRIOV_ATTR_ADDR) {
110 d_vf->vf_lladdr = vf_addr;
113 if (s_vf->ce_mask & SRIOV_ATTR_VLAN) {
114 src_vlans = s_vf->vf_vlans;
115 src_vlan_info = src_vlans->
vlans;
123 dst_vlan_info = dst_vlans->vlans;
125 memcpy(dst_vlan_info, src_vlan_info,
126 dst_vlans->size *
sizeof(*dst_vlan_info));
127 d_vf->vf_vlans = dst_vlans;
130 nl_list_add_head(&d_vf->vf_list, &dest_h->vf_list);
145 vlan_data = vlans->
vlans;
147 while (cur < vlans->size) {
148 nl_dump(p,
"\t vlan %u", vlan_data[cur].vf_vlan);
149 if (vlan_data[cur].vf_vlan_qos)
150 nl_dump(p,
" qos %u", vlan_data[cur].vf_vlan_qos);
151 if (vlan_data[cur].vf_vlan_proto) {
154 rtnl_link_vf_vlanproto2str(prot, buf,
165static void dump_vf_details(
struct rtnl_link_vf *vf_data,
172 nl_dump(p,
"\tvf %u: ", vf_data->vf_index);
173 if (vf_data->ce_mask & SRIOV_ATTR_LINK_STATE) {
174 v = vf_data->vf_linkstate;
176 rtnl_link_vf_linkstate2str(v, buf,
sizeof(buf)));
178 if (vf_data->ce_mask & SRIOV_ATTR_ADDR) {
180 nl_addr2str(vf_data->vf_lladdr, buf,
sizeof(buf)));
184 v = vf_data->vf_spoofchk;
185 nl_dump(p,
"\t spoofchk %s ", v ? SRIOVON : SRIOVOFF);
186 v = vf_data->vf_trust;
187 nl_dump(p,
"trust %s ", v ? SRIOVON : SRIOVOFF);
188 v = vf_data->vf_rss_query_en;
189 nl_dump(p,
"rss_query %s\n", v ? SRIOVON : SRIOVOFF);
194 nl_dump(p,
"\t rate_api old rate %u\n",
197 nl_dump(p,
"\t rate_api new min_rate %u "
198 "max_rate %u\n", vf_rate.min_tx_rate,
199 vf_rate.max_tx_rate);
201 if (vf_data->ce_mask & SRIOV_ATTR_VLAN)
202 dump_sriov_vlans(vf_data->vf_vlans, p);
208void rtnl_link_sriov_dump_details(
struct rtnl_link *link,
212 if (!rtnl_link_has_vf_list(link))
215 nl_dump(p,
" SRIOV VF List\n");
216 list = link->l_vf_list;
217 nl_list_for_each_entry_safe(vf_data, next, &list->vf_list, vf_list) {
218 if (vf_data->ce_mask & SRIOV_ATTR_INDEX)
219 dump_vf_details(vf_data, p);
231 nl_dump(p,
" VF %u Stats:\n", vf_data->vf_index);
232 nl_dump_line(p,
"\tRX: %-14s %-10s %-10s %-10s\n",
233 "bytes",
"packets",
"multicast",
"broadcast");
239 "\t%10.2f %3s %10" PRIu64
" %10" PRIu64
" %10" PRIu64
"\n",
245 nl_dump_line(p,
"\tTX: %-14s %-10s\n",
"bytes",
"packets");
250 nl_dump_line(p,
"\t%10.2f %3s %10" PRIu64
"\n", res, unit,
257void rtnl_link_sriov_dump_stats(
struct rtnl_link *link,
261 list = link->l_vf_list;
262 nl_list_for_each_entry_safe(vf_data, next, &list->vf_list, vf_list) {
263 if (vf_data->ce_mask & SRIOV_ATTR_INDEX)
264 dump_vf_stats(vf_data, p);
272void rtnl_link_sriov_free_data(
struct rtnl_link *link) {
275 if (!rtnl_link_has_vf_list(link))
278 list = link->l_vf_list;
279 nl_list_for_each_entry_safe(vf, next, &list->vf_list, vf_list) {
280 nl_list_del(&vf->vf_list);
290static int rtnl_link_vf_vlan_info(
int len,
struct ifla_vf_vlan_info **vi,
303 vlans->
vlans[cur].
vf_vlan = vi[cur]->vlan ? vi[cur]->vlan : 0;
305 if (vi[cur]->vlan_proto) {
320 struct ifla_vf_vlan vlan;
325 NLA_PUT(msg, IFLA_VF_VLAN,
sizeof(vlan), &vlan);
332static int sriov_fill_vf_vlan_list(
struct nl_msg *msg,
nl_vf_vlans_t *vlans,
336 struct ifla_vf_vlan_info vlan;
343 while (cur < vlans->size) {
344 vlan.vlan = vlan_info[cur].
vf_vlan;
348 NLA_PUT(msg, IFLA_VF_VLAN_INFO,
sizeof(vlan), &vlan);
360static int sriov_fill_vfinfo(
struct nl_msg *msg,
362 int err = 0, new_rate = 0;
365 struct ifla_vf_guid vf_node_guid;
366 struct ifla_vf_guid vf_port_guid;
367 struct ifla_vf_link_state vf_link_state;
368 struct ifla_vf_mac vf_mac;
369 struct ifla_vf_rate new_vf_rate;
370 struct ifla_vf_rss_query_en vf_rss_query_en;
371 struct ifla_vf_spoofchk vf_spoofchk;
372 struct ifla_vf_trust vf_trust;
373 struct ifla_vf_tx_rate vf_rate;
377 if (!(vf_data->ce_mask & SRIOV_ATTR_INDEX))
378 return -NLE_MISSING_ATTR;
384 if (vf_data->ce_mask & SRIOV_ATTR_ADDR) {
385 vf_mac.vf = vf_data->vf_index;
386 memset(vf_mac.mac, 0,
sizeof(vf_mac.mac));
389 NLA_PUT(msg, IFLA_VF_MAC,
sizeof(vf_mac), &vf_mac);
393 if (vf_data->ce_mask & SRIOV_ATTR_VLAN) {
394 vlan_list = vf_data->vf_vlans;
395 vlan_info = vlan_list->
vlans;
400 if ((vlan_list->
size == 1) && (proto == ETH_P_8021Q))
401 sriov_fill_vf_vlan(msg, vlan_info, vf_data->vf_index);
403 err = sriov_fill_vf_vlan_list(msg, vlan_list,
408 if (vf_data->ce_mask & SRIOV_ATTR_TX_RATE) {
409 vf_rate.vf = vf_data->vf_index;
410 vf_rate.rate = vf_data->vf_rate;
412 NLA_PUT(msg, IFLA_VF_TX_RATE,
sizeof(vf_rate), &vf_rate);
416 new_vf_rate.min_tx_rate = 0;
417 new_vf_rate.max_tx_rate = 0;
418 new_vf_rate.vf = vf_data->vf_index;
419 if (vf_data->ce_mask & SRIOV_ATTR_RATE_MIN) {
420 new_vf_rate.min_tx_rate = vf_data->vf_min_tx_rate;
423 if (vf_data->ce_mask & SRIOV_ATTR_RATE_MAX) {
424 new_vf_rate.max_tx_rate = vf_data->vf_max_tx_rate;
428 NLA_PUT(msg, IFLA_VF_RATE,
sizeof(new_vf_rate), &new_vf_rate);
431 if (vf_data->ce_mask & SRIOV_ATTR_SPOOFCHK) {
432 vf_spoofchk.vf = vf_data->vf_index;
433 vf_spoofchk.setting = vf_data->vf_spoofchk;
435 NLA_PUT(msg, IFLA_VF_SPOOFCHK,
sizeof(vf_spoofchk),
440 if (vf_data->ce_mask & SRIOV_ATTR_LINK_STATE) {
441 vf_link_state.vf = vf_data->vf_index;
442 vf_link_state.link_state = vf_data->vf_linkstate;
444 NLA_PUT(msg, IFLA_VF_LINK_STATE,
sizeof(vf_link_state),
449 if (vf_data->ce_mask & SRIOV_ATTR_RSS_QUERY_EN) {
450 vf_rss_query_en.vf = vf_data->vf_index;
451 vf_rss_query_en.setting = vf_data->vf_rss_query_en;
453 NLA_PUT(msg, IFLA_VF_RSS_QUERY_EN,
sizeof(vf_rss_query_en),
458 if (vf_data->ce_mask & SRIOV_ATTR_TRUST) {
459 vf_trust.vf = vf_data->vf_index;
460 vf_trust.setting = vf_data->vf_trust;
462 NLA_PUT(msg, IFLA_VF_TRUST,
sizeof(vf_trust), &vf_trust);
466 if (vf_data->ce_mask & SRIOV_ATTR_IB_NODE_GUID) {
467 vf_node_guid.vf = vf_data->vf_index;
468 vf_node_guid.guid = vf_data->vf_guid_node;
470 NLA_PUT(msg, IFLA_VF_IB_NODE_GUID,
sizeof(vf_node_guid),
475 if (vf_data->ce_mask & SRIOV_ATTR_IB_PORT_GUID) {
476 vf_port_guid.vf = vf_data->vf_index;
477 vf_port_guid.guid = vf_data->vf_guid_port;
479 NLA_PUT(msg, IFLA_VF_IB_PORT_GUID,
sizeof(vf_port_guid),
490int rtnl_link_sriov_fill_vflist(
struct nl_msg *msg,
struct rtnl_link *link) {
495 if (!(err = rtnl_link_has_vf_list(link)))
501 list = link->l_vf_list;
502 nl_list_for_each_entry_safe(vf, next, &list->vf_list, vf_list) {
503 if (vf->ce_mask & SRIOV_ATTR_INDEX) {
504 if ((err = sriov_fill_vfinfo(msg, vf)) < 0)
505 goto nla_nest_list_failure;
509nla_nest_list_failure:
516int rtnl_link_sriov_parse_vflist(
struct rtnl_link *link,
struct nlattr **tb) {
517 int err, len, list_len, list_rem;
518 struct ifla_vf_mac *vf_lladdr;
519 struct ifla_vf_vlan *vf_vlan;
520 struct ifla_vf_vlan_info *vf_vlan_info[MAX_VLAN_LIST_LEN];
521 struct ifla_vf_tx_rate *vf_tx_rate;
522 struct ifla_vf_spoofchk *vf_spoofchk;
523 struct ifla_vf_link_state *vf_linkstate;
524 struct ifla_vf_rate *vf_rate;
525 struct ifla_vf_rss_query_en *vf_rss_query;
526 struct ifla_vf_trust *vf_trust;
527 struct nlattr *nla, *nla_list, *t[IFLA_VF_MAX+1],
528 *stb[RTNL_LINK_VF_STATS_MAX+1];
532 len =
nla_len(tb[IFLA_VFINFO_LIST]);
534 if (!link->l_vf_list)
536 vf_head = link->l_vf_list;
549 if (t[IFLA_VF_MAC]) {
550 vf_lladdr =
nla_data(t[IFLA_VF_MAC]);
552 vf_data->vf_index = vf_lladdr->vf;
553 vf_data->ce_mask |= SRIOV_ATTR_INDEX;
557 if (vf_data->vf_lladdr == NULL) {
562 vf_data->ce_mask |= SRIOV_ATTR_ADDR;
565 if (t[IFLA_VF_VLAN_LIST]) {
569 if (list_len >= MAX_VLAN_LIST_LEN)
571 vf_vlan_info[list_len] =
nla_data(nla_list);
575 err = rtnl_link_vf_vlan_info(list_len, vf_vlan_info,
582 vf_data->vf_vlans = vf_vlans;
583 vf_data->ce_mask |= SRIOV_ATTR_VLAN;
584 }
else if (t[IFLA_VF_VLAN]) {
585 vf_vlan =
nla_data(t[IFLA_VF_VLAN]);
598 vf_data->vf_vlans = vf_vlans;
599 vf_data->ce_mask |= SRIOV_ATTR_VLAN;
603 if (t[IFLA_VF_TX_RATE]) {
604 vf_tx_rate =
nla_data(t[IFLA_VF_TX_RATE]);
606 if (vf_tx_rate->rate) {
607 vf_data->vf_rate = vf_tx_rate->rate;
608 vf_data->ce_mask |= SRIOV_ATTR_TX_RATE;
612 if (t[IFLA_VF_SPOOFCHK]) {
613 vf_spoofchk =
nla_data(t[IFLA_VF_SPOOFCHK]);
615 if (vf_spoofchk->setting != -1) {
616 vf_data->vf_spoofchk = vf_spoofchk->setting ? 1 : 0;
617 vf_data->ce_mask |= SRIOV_ATTR_SPOOFCHK;
621 if (t[IFLA_VF_LINK_STATE]) {
622 vf_linkstate =
nla_data(t[IFLA_VF_LINK_STATE]);
624 vf_data->vf_linkstate = vf_linkstate->link_state;
625 vf_data->ce_mask |= SRIOV_ATTR_LINK_STATE;
628 if (t[IFLA_VF_RATE]) {
629 vf_rate =
nla_data(t[IFLA_VF_RATE]);
631 if (vf_rate->max_tx_rate) {
632 vf_data->vf_max_tx_rate = vf_rate->max_tx_rate;
633 vf_data->ce_mask |= SRIOV_ATTR_RATE_MAX;
635 if (vf_rate->min_tx_rate) {
636 vf_data->vf_min_tx_rate = vf_rate->min_tx_rate;
637 vf_data->ce_mask |= SRIOV_ATTR_RATE_MIN;
641 if (t[IFLA_VF_RSS_QUERY_EN]) {
642 vf_rss_query =
nla_data(t[IFLA_VF_RSS_QUERY_EN]);
644 if (vf_rss_query->setting != -1) {
645 vf_data->vf_rss_query_en = vf_rss_query->setting ? 1 : 0;
646 vf_data->ce_mask |= SRIOV_ATTR_RSS_QUERY_EN;
650 if (t[IFLA_VF_STATS]) {
659 SET_VF_STAT(link, cur, stb,
661 IFLA_VF_STATS_RX_PACKETS);
662 SET_VF_STAT(link, cur, stb,
664 IFLA_VF_STATS_TX_PACKETS);
665 SET_VF_STAT(link, cur, stb,
667 IFLA_VF_STATS_RX_BYTES);
668 SET_VF_STAT(link, cur, stb,
670 IFLA_VF_STATS_TX_BYTES);
671 SET_VF_STAT(link, cur, stb,
673 IFLA_VF_STATS_BROADCAST);
674 SET_VF_STAT(link, cur, stb,
676 IFLA_VF_STATS_MULTICAST);
678 vf_data->ce_mask |= SRIOV_ATTR_STATS;
681 if (t[IFLA_VF_TRUST]) {
682 vf_trust =
nla_data(t[IFLA_VF_TRUST]);
684 if (vf_trust->setting != -1) {
685 vf_data->vf_trust = vf_trust->setting ? 1 : 0;
686 vf_data->ce_mask |= SRIOV_ATTR_TRUST;
690 nl_list_add_head(&vf_data->vf_list, &vf_head->vf_list);
715 return -NLE_OBJ_NOTFOUND;
717 if (!link->l_vf_list) {
719 if (!link->l_vf_list)
724 vf_head->ce_refcnt++;
726 vf_head = link->l_vf_list;
727 nl_list_add_head(&vf_data->vf_list, &vf_head->vf_list);
728 link->l_vf_list = vf_head;
730 rtnl_link_set_vf_list(link);
749 if (!(vf = calloc(1,
sizeof(*vf))))
752 NL_INIT_LIST_HEAD(&vf->vf_list);
755 NL_DBG(4,
"Allocated new SRIOV VF object %p\n", vf);
768 if (vf_data->ce_refcnt > 0)
769 NL_DBG(1,
"Warning: Freeing SRIOV VF object in use...\n");
771 if (vf_data->ce_mask & SRIOV_ATTR_ADDR)
773 if (vf_data->ce_mask & SRIOV_ATTR_VLAN)
776 NL_DBG(4,
"Freed SRIOV VF object %p\n", vf_data);
796 list = link->l_vf_list;
797 nl_list_for_each_entry_safe(vf, next, &list->vf_list, vf_list) {
798 if (vf->vf_index == vf_num) {
806 NL_DBG(4,
"New reference to SRIOV VF object %p, total %i\n",
807 ret, ret->ce_refcnt);
824 vf_data->ce_refcnt--;
825 NL_DBG(4,
"Returned SRIOV VF object reference %p, %i remaining\n",
826 vf_data, vf_data->ce_refcnt);
828 if (vf_data->ce_refcnt < 0)
831 if (vf_data->ce_refcnt <= 0)
853 return -NLE_OBJ_NOTFOUND;
855 if (vf_data->ce_mask & SRIOV_ATTR_ADDR)
856 *addr = vf_data->vf_lladdr;
874 if (vf_data->vf_lladdr)
878 vf_data->vf_lladdr = addr;
879 vf_data->ce_mask |= SRIOV_ATTR_ADDR;
891 vf_data->vf_guid_node = guid;
892 vf_data->ce_mask |= SRIOV_ATTR_IB_NODE_GUID;
904 vf_data->vf_guid_port = guid;
905 vf_data->ce_mask |= SRIOV_ATTR_IB_PORT_GUID;
924 return -NLE_OBJ_NOTFOUND;
926 if (vf_data->ce_mask & SRIOV_ATTR_INDEX)
927 *vf_index = vf_data->vf_index;
943 vf_data->vf_index = vf_index;
944 vf_data->ce_mask |= SRIOV_ATTR_INDEX;
962 uint32_t *vf_linkstate)
965 return -NLE_OBJ_NOTFOUND;
967 if (vf_data->ce_mask & SRIOV_ATTR_LINK_STATE)
968 *vf_linkstate = vf_data->vf_linkstate;
986 uint32_t vf_linkstate) {
987 vf_data->vf_linkstate = vf_linkstate;
988 vf_data->ce_mask |= SRIOV_ATTR_LINK_STATE;
1023 return -NLE_OBJ_NOTFOUND;
1030 if (vf_data->ce_mask & SRIOV_ATTR_RATE_MAX) {
1031 if (vf_data->vf_max_tx_rate) {
1037 if (vf_data->ce_mask & SRIOV_ATTR_RATE_MIN) {
1038 if (vf_data->vf_min_tx_rate) {
1044 if ((!set) && (vf_data->ce_mask & SRIOV_ATTR_TX_RATE)) {
1045 if (vf_data->vf_rate) {
1047 vf_rate->
rate = vf_data->vf_rate;
1086 vf_data->vf_rate = vf_rate->
rate;
1087 vf_data->ce_mask |= SRIOV_ATTR_TX_RATE;
1090 vf_data->ce_mask |= SRIOV_ATTR_RATE_MAX;
1093 vf_data->ce_mask |= SRIOV_ATTR_RATE_MIN;
1112 uint32_t *vf_rss_query_en)
1115 return -NLE_OBJ_NOTFOUND;
1117 if (vf_data->ce_mask & SRIOV_ATTR_RSS_QUERY_EN)
1118 *vf_rss_query_en = vf_data->vf_rss_query_en;
1133 uint32_t vf_rss_query_en) {
1134 vf_data->vf_rss_query_en = vf_rss_query_en;
1135 vf_data->ce_mask |= SRIOV_ATTR_RSS_QUERY_EN;
1153 uint32_t *vf_spoofchk)
1156 return -NLE_OBJ_NOTFOUND;
1158 if (vf_data->ce_mask & SRIOV_ATTR_SPOOFCHK)
1159 *vf_spoofchk = vf_data->vf_spoofchk;
1174 uint32_t vf_spoofchk) {
1175 vf_data->vf_spoofchk = vf_spoofchk;
1176 vf_data->ce_mask |= SRIOV_ATTR_SPOOFCHK;
1197 return -NLE_OBJ_NOTFOUND;
1199 if (vf_data->ce_mask & SRIOV_ATTR_STATS)
1200 *vf_stat = vf_data->vf_stats[stat];
1222 return -NLE_OBJ_NOTFOUND;
1224 if (vf_data->ce_mask & SRIOV_ATTR_TRUST)
1225 *vf_trust = vf_data->vf_trust;
1240 vf_data->vf_trust = vf_trust;
1241 vf_data->ce_mask |= SRIOV_ATTR_TRUST;
1266 return -NLE_OBJ_NOTFOUND;
1268 if (vf_data->ce_mask & SRIOV_ATTR_VLAN) {
1269 vf = vf_data->vf_vlans;
1292 if (!vf_data||!vf_vlans)
1295 vf_data->vf_vlans = vf_vlans;
1296 vf_data->vf_vlans->ce_refcnt++;
1297 vf_data->ce_mask |= SRIOV_ATTR_VLAN;
1318 if (vlan_count > MAX_VLAN_LIST_LEN)
1321 vlans = calloc(1,
sizeof(*vlans));
1325 vlan_info = calloc(vlan_count+1,
sizeof(*vlan_info));
1331 NL_DBG(4,
"Allocated new SRIOV VF VLANs object %p\n", vlans);
1334 vlans->
size = vlan_count;
1335 vlans->
vlans = vlan_info;
1350 NL_DBG(1,
"Warning: Freeing SRIOV VF VLANs object in use...\n");
1352 NL_DBG(4,
"Freed SRIOV VF object %p\n", vf_vlans);
1353 free(vf_vlans->
vlans);
1368 NL_DBG(4,
"Returned SRIOV VF VLANs object reference %p, %i remaining\n",
1387static const struct trans_tbl vf_link_states[] = {
1388 __ADD(IFLA_VF_LINK_STATE_AUTO, autodetect),
1389 __ADD(IFLA_VF_LINK_STATE_ENABLE, up),
1390 __ADD(IFLA_VF_LINK_STATE_DISABLE, down),
1393char *rtnl_link_vf_linkstate2str(uint32_t ls,
char *buf,
size_t len)
1395 return __type2str(ls, buf, len, vf_link_states,
1396 ARRAY_SIZE(vf_link_states));
1399int rtnl_link_vf_str2linkstate(
const char *name)
1401 return __str2type(name, vf_link_states, ARRAY_SIZE(vf_link_states));
1404static const struct trans_tbl vf_vlan_proto[] = {
1405 __ADD(ETH_P_8021Q, 8021Q),
1406 __ADD(ETH_P_8021AD, 8021AD),
1409char *rtnl_link_vf_vlanproto2str(uint16_t proto,
char *buf,
size_t len)
1411 return __type2str(proto, buf, len, vf_vlan_proto,
1412 ARRAY_SIZE(vf_vlan_proto));
1415int rtnl_link_vf_str2vlanproto(
const char *name)
1417 return __str2type(name, vf_vlan_proto, ARRAY_SIZE(vf_vlan_proto));
1428int rtnl_link_vf_str2guid(uint64_t *guid,
const char *guid_s) {
1429 unsigned long int tmp;
1433 if (strlen(guid_s) != RTNL_VF_GUID_STR_LEN)
1436 for (i = 0; i < 7; i++) {
1437 if (guid_s[2 + i * 3] !=
':')
1442 for (i = 0; i < 8; i++) {
1443 tmp = strtoul(guid_s + i * 3, &endptr, 16);
1444 if (endptr != guid_s + i * 3 + 2)
1450 *guid |= tmp << (56 - 8 * i);
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
struct nl_addr * nl_addr_build(int family, const void *buf, size_t size)
Allocate abstract address based on a binary address.
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
unsigned int nl_addr_get_len(const struct nl_addr *addr)
Get length of binary address of abstract address object.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
void nl_addr_set_family(struct nl_addr *addr, int family)
Set address family.
struct nlattr * nla_next(const struct nlattr *nla, int *remaining)
Return next attribute in a stream of attributes.
int nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head, int len, const struct nla_policy *policy)
Create attribute index based on a stream of attributes.
int nla_ok(const struct nlattr *nla, int remaining)
Check if the attribute header and payload can be accessed safely.
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
#define nla_for_each_nested(pos, nla, rem)
Iterate over a stream of nested attributes.
int nla_len(const struct nlattr *nla)
Return length of the payload .
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
@ NLA_NESTED
Nested attributes.
int rtnl_link_vf_get_rss_query_en(struct rtnl_link_vf *vf_data, uint32_t *vf_rss_query_en)
Get RSS Query EN value of SRIOV Virtual Function.
int rtnl_link_vf_get_index(struct rtnl_link_vf *vf_data, uint32_t *vf_index)
Get index of SRIOV Virtual Function.
void rtnl_link_vf_set_addr(struct rtnl_link_vf *vf_data, struct nl_addr *addr)
Set link layer address of SRIOV Virtual Function object.
void rtnl_link_vf_set_vlans(struct rtnl_link_vf *vf_data, nl_vf_vlans_t *vf_vlans)
Add a SRIOV VF VLANs object to the SRIOV Virtual Function Object.
int rtnl_link_vf_vlan_alloc(nl_vf_vlans_t **vf_vlans, int vlan_count)
Allocate a SRIOV VF VLAN object.
void rtnl_link_vf_put(struct rtnl_link_vf *vf_data)
Return SRIOV VF object to the owning link object.
struct rtnl_link_vf * rtnl_link_vf_get(struct rtnl_link *link, uint32_t vf_num)
Lookup SRIOV VF in link object by VF index.
void rtnl_link_vf_set_ib_node_guid(struct rtnl_link_vf *vf_data, uint64_t guid)
Set the Infiniband node GUID for the SRIOV Virtual Function object.
void rtnl_link_vf_set_trust(struct rtnl_link_vf *vf_data, uint32_t vf_trust)
Set user trust setting on SRIOV Virtual Function Object.
int rtnl_link_vf_get_addr(struct rtnl_link_vf *vf_data, struct nl_addr **addr)
Get link layer address of SRIOV Virtual Function.
void rtnl_link_vf_set_ib_port_guid(struct rtnl_link_vf *vf_data, uint64_t guid)
Set the Infiniband port GUID for the SRIOV Virtual Function object.
void rtnl_link_vf_set_rate(struct rtnl_link_vf *vf_data, struct nl_vf_rate *vf_rate)
Set TX Rate Limit of SRIOV Virtual Function object.
void rtnl_link_vf_set_linkstate(struct rtnl_link_vf *vf_data, uint32_t vf_linkstate)
Set link state of SRIOV Virtual Function object.
void rtnl_link_vf_set_rss_query_en(struct rtnl_link_vf *vf_data, uint32_t vf_rss_query_en)
Set RSS configuration querying of SRIOV Virtual Function Object.
int rtnl_link_vf_get_vlans(struct rtnl_link_vf *vf_data, nl_vf_vlans_t **vf_vlans)
Get an array of VLANS on SRIOV Virtual Function.
int rtnl_link_vf_get_stat(struct rtnl_link_vf *vf_data, rtnl_link_vf_stats_t stat, uint64_t *vf_stat)
Get value of stat counter for SRIOV Virtual Function.
void rtnl_link_vf_vlan_put(nl_vf_vlans_t *vf_vlans)
Return SRIOV VF VLANs object to the owning SRIOV VF object.
void rtnl_link_vf_set_spoofchk(struct rtnl_link_vf *vf_data, uint32_t vf_spoofchk)
Set spoof checking value of SRIOV Virtual Function Object.
int rtnl_link_vf_get_trust(struct rtnl_link_vf *vf_data, uint32_t *vf_trust)
Get trust setting of SRIOV Virtual Function.
void rtnl_link_vf_free(struct rtnl_link_vf *vf_data)
Free SRIOV VF object.
struct rtnl_link_vf * rtnl_link_vf_alloc(void)
Allocate a new SRIOV VF object.
int rtnl_link_vf_get_spoofchk(struct rtnl_link_vf *vf_data, uint32_t *vf_spoofchk)
Get spoof checking value of SRIOV Virtual Function.
void rtnl_link_vf_set_index(struct rtnl_link_vf *vf_data, uint32_t vf_index)
Set index of SRIOV Virtual Function object.
void rtnl_link_vf_vlan_free(nl_vf_vlans_t *vf_vlans)
Free an allocated SRIOV VF VLANs object.
int rtnl_link_vf_get_linkstate(struct rtnl_link_vf *vf_data, uint32_t *vf_linkstate)
Get link state of SRIOV Virtual Function.
int rtnl_link_vf_get_rate(struct rtnl_link_vf *vf_data, struct nl_vf_rate *vf_rate)
Get TX Rate Limit of SRIOV Virtual Function.
int rtnl_link_vf_add(struct rtnl_link *link, struct rtnl_link_vf *vf_data)
Add a SRIOV VF object to a link object.
@ RTNL_LINK_VF_STATS_TX_BYTES
@ RTNL_LINK_VF_STATS_BROADCAST
@ RTNL_LINK_VF_STATS_RX_PACKETS
@ RTNL_LINK_VF_STATS_MULTICAST
@ RTNL_LINK_VF_STATS_RX_BYTES
@ RTNL_LINK_VF_STATS_TX_PACKETS
@ RTNL_LINK_VF_RATE_API_UNSPEC
@ RTNL_LINK_VF_RATE_API_NEW
@ RTNL_LINK_VF_RATE_API_OLD
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
double nl_cancel_down_bytes(unsigned long long l, char **unit)
Cancel down a byte counter.
VF Rate information structure.
SRIOV VF VLANs information.
nl_vf_vlan_info_t * vlans
Attribute validation policy.
uint16_t minlen
Minimal length of payload required.
uint16_t type
Type of attribute or NLA_UNSPEC.