Lines Matching refs:link
69 static struct rtnl_link_af_ops *af_lookup_and_alloc(struct rtnl_link *link, in af_lookup_and_alloc() argument
79 if (!(data = rtnl_link_af_alloc(link, af_ops))) { in af_lookup_and_alloc()
87 static int af_free(struct rtnl_link *link, struct rtnl_link_af_ops *ops, in af_free() argument
91 ops->ao_free(link, data); in af_free()
98 static int af_clone(struct rtnl_link *link, struct rtnl_link_af_ops *ops, in af_clone() argument
110 static int af_fill(struct rtnl_link *link, struct rtnl_link_af_ops *ops, in af_fill() argument
123 if ((err = ops->ao_fill_af(link, arg, data)) < 0) in af_fill()
131 static int af_dump_line(struct rtnl_link *link, struct rtnl_link_af_ops *ops, in af_dump_line() argument
137 ops->ao_dump[NL_DUMP_LINE](link, p, data); in af_dump_line()
142 static int af_dump_details(struct rtnl_link *link, struct rtnl_link_af_ops *ops, in af_dump_details() argument
148 ops->ao_dump[NL_DUMP_DETAILS](link, p, data); in af_dump_details()
153 static int af_dump_stats(struct rtnl_link *link, struct rtnl_link_af_ops *ops, in af_dump_stats() argument
159 ops->ao_dump[NL_DUMP_STATS](link, p, data); in af_dump_stats()
164 static int do_foreach_af(struct rtnl_link *link, in do_foreach_af() argument
172 if (link->l_af_data[i]) { in do_foreach_af()
178 err = cb(link, ops, link->l_af_data[i], arg); in do_foreach_af()
190 static void release_link_info(struct rtnl_link *link) in release_link_info() argument
192 struct rtnl_link_info_ops *io = link->l_info_ops; in release_link_info()
196 io->io_free(link); in release_link_info()
199 BUG_ON(link->l_info); in release_link_info()
202 link->l_info_ops = NULL; in release_link_info()
208 struct rtnl_link *link = nl_object_priv(c); in link_free_data() local
210 if (link) { in link_free_data()
213 if ((io = link->l_info_ops) != NULL) in link_free_data()
214 release_link_info(link); in link_free_data()
217 rtnl_link_af_ops_put(link->l_af_ops); in link_free_data()
219 nl_addr_put(link->l_addr); in link_free_data()
220 nl_addr_put(link->l_bcast); in link_free_data()
222 free(link->l_ifalias); in link_free_data()
223 free(link->l_info_kind); in link_free_data()
225 do_foreach_af(link, af_free, NULL); in link_free_data()
227 nl_data_free(link->l_phys_port_id); in link_free_data()
304 int rtnl_link_info_parse(struct rtnl_link *link, struct nlattr **tb) in rtnl_link_info_parse() argument
309 nla_strlcpy(link->l_name, tb[IFLA_IFNAME], IFNAMSIZ); in rtnl_link_info_parse()
315 link->l_stats[RTNL_LINK_RX_PACKETS] = st->rx_packets; in rtnl_link_info_parse()
316 link->l_stats[RTNL_LINK_TX_PACKETS] = st->tx_packets; in rtnl_link_info_parse()
317 link->l_stats[RTNL_LINK_RX_BYTES] = st->rx_bytes; in rtnl_link_info_parse()
318 link->l_stats[RTNL_LINK_TX_BYTES] = st->tx_bytes; in rtnl_link_info_parse()
319 link->l_stats[RTNL_LINK_RX_ERRORS] = st->rx_errors; in rtnl_link_info_parse()
320 link->l_stats[RTNL_LINK_TX_ERRORS] = st->tx_errors; in rtnl_link_info_parse()
321 link->l_stats[RTNL_LINK_RX_DROPPED] = st->rx_dropped; in rtnl_link_info_parse()
322 link->l_stats[RTNL_LINK_TX_DROPPED] = st->tx_dropped; in rtnl_link_info_parse()
323 link->l_stats[RTNL_LINK_MULTICAST] = st->multicast; in rtnl_link_info_parse()
324 link->l_stats[RTNL_LINK_COLLISIONS] = st->collisions; in rtnl_link_info_parse()
326 link->l_stats[RTNL_LINK_RX_LEN_ERR] = st->rx_length_errors; in rtnl_link_info_parse()
327 link->l_stats[RTNL_LINK_RX_OVER_ERR] = st->rx_over_errors; in rtnl_link_info_parse()
328 link->l_stats[RTNL_LINK_RX_CRC_ERR] = st->rx_crc_errors; in rtnl_link_info_parse()
329 link->l_stats[RTNL_LINK_RX_FRAME_ERR] = st->rx_frame_errors; in rtnl_link_info_parse()
330 link->l_stats[RTNL_LINK_RX_FIFO_ERR] = st->rx_fifo_errors; in rtnl_link_info_parse()
331 link->l_stats[RTNL_LINK_RX_MISSED_ERR] = st->rx_missed_errors; in rtnl_link_info_parse()
333 link->l_stats[RTNL_LINK_TX_ABORT_ERR] = st->tx_aborted_errors; in rtnl_link_info_parse()
334 link->l_stats[RTNL_LINK_TX_CARRIER_ERR] = st->tx_carrier_errors; in rtnl_link_info_parse()
335 link->l_stats[RTNL_LINK_TX_FIFO_ERR] = st->tx_fifo_errors; in rtnl_link_info_parse()
336 link->l_stats[RTNL_LINK_TX_HBEAT_ERR] = st->tx_heartbeat_errors; in rtnl_link_info_parse()
337 link->l_stats[RTNL_LINK_TX_WIN_ERR] = st->tx_window_errors; in rtnl_link_info_parse()
339 link->l_stats[RTNL_LINK_RX_COMPRESSED] = st->rx_compressed; in rtnl_link_info_parse()
340 link->l_stats[RTNL_LINK_TX_COMPRESSED] = st->tx_compressed; in rtnl_link_info_parse()
342 link->ce_mask |= LINK_ATTR_STATS; in rtnl_link_info_parse()
358 link->l_stats[RTNL_LINK_RX_PACKETS] = st.rx_packets; in rtnl_link_info_parse()
359 link->l_stats[RTNL_LINK_TX_PACKETS] = st.tx_packets; in rtnl_link_info_parse()
360 link->l_stats[RTNL_LINK_RX_BYTES] = st.rx_bytes; in rtnl_link_info_parse()
361 link->l_stats[RTNL_LINK_TX_BYTES] = st.tx_bytes; in rtnl_link_info_parse()
362 link->l_stats[RTNL_LINK_RX_ERRORS] = st.rx_errors; in rtnl_link_info_parse()
363 link->l_stats[RTNL_LINK_TX_ERRORS] = st.tx_errors; in rtnl_link_info_parse()
364 link->l_stats[RTNL_LINK_RX_DROPPED] = st.rx_dropped; in rtnl_link_info_parse()
365 link->l_stats[RTNL_LINK_TX_DROPPED] = st.tx_dropped; in rtnl_link_info_parse()
366 link->l_stats[RTNL_LINK_MULTICAST] = st.multicast; in rtnl_link_info_parse()
367 link->l_stats[RTNL_LINK_COLLISIONS] = st.collisions; in rtnl_link_info_parse()
369 link->l_stats[RTNL_LINK_RX_LEN_ERR] = st.rx_length_errors; in rtnl_link_info_parse()
370 link->l_stats[RTNL_LINK_RX_OVER_ERR] = st.rx_over_errors; in rtnl_link_info_parse()
371 link->l_stats[RTNL_LINK_RX_CRC_ERR] = st.rx_crc_errors; in rtnl_link_info_parse()
372 link->l_stats[RTNL_LINK_RX_FRAME_ERR] = st.rx_frame_errors; in rtnl_link_info_parse()
373 link->l_stats[RTNL_LINK_RX_FIFO_ERR] = st.rx_fifo_errors; in rtnl_link_info_parse()
374 link->l_stats[RTNL_LINK_RX_MISSED_ERR] = st.rx_missed_errors; in rtnl_link_info_parse()
376 link->l_stats[RTNL_LINK_TX_ABORT_ERR] = st.tx_aborted_errors; in rtnl_link_info_parse()
377 link->l_stats[RTNL_LINK_TX_CARRIER_ERR] = st.tx_carrier_errors; in rtnl_link_info_parse()
378 link->l_stats[RTNL_LINK_TX_FIFO_ERR] = st.tx_fifo_errors; in rtnl_link_info_parse()
379 link->l_stats[RTNL_LINK_TX_HBEAT_ERR] = st.tx_heartbeat_errors; in rtnl_link_info_parse()
380 link->l_stats[RTNL_LINK_TX_WIN_ERR] = st.tx_window_errors; in rtnl_link_info_parse()
382 link->l_stats[RTNL_LINK_RX_COMPRESSED] = st.rx_compressed; in rtnl_link_info_parse()
383 link->l_stats[RTNL_LINK_TX_COMPRESSED] = st.tx_compressed; in rtnl_link_info_parse()
385 link->ce_mask |= LINK_ATTR_STATS; in rtnl_link_info_parse()
389 link->l_txqlen = nla_get_u32(tb[IFLA_TXQLEN]); in rtnl_link_info_parse()
390 link->ce_mask |= LINK_ATTR_TXQLEN; in rtnl_link_info_parse()
394 link->l_mtu = nla_get_u32(tb[IFLA_MTU]); in rtnl_link_info_parse()
395 link->ce_mask |= LINK_ATTR_MTU; in rtnl_link_info_parse()
399 link->l_addr = nl_addr_alloc_attr(tb[IFLA_ADDRESS], AF_UNSPEC); in rtnl_link_info_parse()
400 if (link->l_addr == NULL) in rtnl_link_info_parse()
402 nl_addr_set_family(link->l_addr, in rtnl_link_info_parse()
403 nl_addr_guess_family(link->l_addr)); in rtnl_link_info_parse()
404 link->ce_mask |= LINK_ATTR_ADDR; in rtnl_link_info_parse()
408 link->l_bcast = nl_addr_alloc_attr(tb[IFLA_BROADCAST], in rtnl_link_info_parse()
410 if (link->l_bcast == NULL) in rtnl_link_info_parse()
412 nl_addr_set_family(link->l_bcast, in rtnl_link_info_parse()
413 nl_addr_guess_family(link->l_bcast)); in rtnl_link_info_parse()
414 link->ce_mask |= LINK_ATTR_BRD; in rtnl_link_info_parse()
418 link->l_link = nla_get_u32(tb[IFLA_LINK]); in rtnl_link_info_parse()
419 link->ce_mask |= LINK_ATTR_LINK; in rtnl_link_info_parse()
423 link->l_weight = nla_get_u32(tb[IFLA_WEIGHT]); in rtnl_link_info_parse()
424 link->ce_mask |= LINK_ATTR_WEIGHT; in rtnl_link_info_parse()
428 nla_strlcpy(link->l_qdisc, tb[IFLA_QDISC], IFQDISCSIZ); in rtnl_link_info_parse()
429 link->ce_mask |= LINK_ATTR_QDISC; in rtnl_link_info_parse()
433 nla_memcpy(&link->l_map, tb[IFLA_MAP], in rtnl_link_info_parse()
435 link->ce_mask |= LINK_ATTR_MAP; in rtnl_link_info_parse()
439 link->l_master = nla_get_u32(tb[IFLA_MASTER]); in rtnl_link_info_parse()
440 link->ce_mask |= LINK_ATTR_MASTER; in rtnl_link_info_parse()
444 link->l_carrier = nla_get_u8(tb[IFLA_CARRIER]); in rtnl_link_info_parse()
445 link->ce_mask |= LINK_ATTR_CARRIER; in rtnl_link_info_parse()
449 link->l_operstate = nla_get_u8(tb[IFLA_OPERSTATE]); in rtnl_link_info_parse()
450 link->ce_mask |= LINK_ATTR_OPERSTATE; in rtnl_link_info_parse()
454 link->l_linkmode = nla_get_u8(tb[IFLA_LINKMODE]); in rtnl_link_info_parse()
455 link->ce_mask |= LINK_ATTR_LINKMODE; in rtnl_link_info_parse()
459 link->l_ifalias = nla_strdup(tb[IFLA_IFALIAS]); in rtnl_link_info_parse()
460 if (link->l_ifalias == NULL) in rtnl_link_info_parse()
462 link->ce_mask |= LINK_ATTR_IFALIAS; in rtnl_link_info_parse()
466 link->l_ns_fd = nla_get_u32(tb[IFLA_NET_NS_FD]); in rtnl_link_info_parse()
467 link->ce_mask |= LINK_ATTR_NS_FD; in rtnl_link_info_parse()
471 link->l_ns_pid = nla_get_u32(tb[IFLA_NET_NS_PID]); in rtnl_link_info_parse()
472 link->ce_mask |= LINK_ATTR_NS_PID; in rtnl_link_info_parse()
481 struct rtnl_link *link; in link_msg_parser() local
490 link = rtnl_link_alloc(); in link_msg_parser()
491 if (link == NULL) { in link_msg_parser()
496 link->ce_msgtype = n->nlmsg_type; in link_msg_parser()
502 link->l_family = family = ifi->ifi_family; in link_msg_parser()
503 link->l_arptype = ifi->ifi_type; in link_msg_parser()
504 link->l_index = ifi->ifi_index; in link_msg_parser()
505 link->l_flags = ifi->ifi_flags; in link_msg_parser()
506 link->l_change = ifi->ifi_change; in link_msg_parser()
507 link->ce_mask = (LINK_ATTR_IFNAME | LINK_ATTR_FAMILY | in link_msg_parser()
511 if ((af_ops = af_lookup_and_alloc(link, family))) { in link_msg_parser()
518 link->l_af_ops = af_ops; in link_msg_parser()
525 err = rtnl_link_info_parse(link, tb); in link_msg_parser()
530 link->l_num_vf = nla_get_u32(tb[IFLA_NUM_VF]); in link_msg_parser()
531 link->ce_mask |= LINK_ATTR_NUM_VF; in link_msg_parser()
547 err = rtnl_link_set_type(link, kind); in link_msg_parser()
552 !af_ops && (af_ops = af_lookup_and_alloc(link, af))) { in link_msg_parser()
557 link->l_family = family = af; in link_msg_parser()
558 link->l_af_ops = af_ops; in link_msg_parser()
562 link->l_info_ops = ops; in link_msg_parser()
567 err = ops->io_parse(link, li[IFLA_INFO_DATA], in link_msg_parser()
576 link->ce_mask |= LINK_ATTR_LINKINFO; in link_msg_parser()
580 err = af_ops->ao_parse_protinfo(link, tb[IFLA_PROTINFO], in link_msg_parser()
581 link->l_af_data[link->l_family]); in link_msg_parser()
584 link->ce_mask |= LINK_ATTR_PROTINFO; in link_msg_parser()
592 af_ops = af_lookup_and_alloc(link, nla_type(af_attr)); in link_msg_parser()
594 char *af_data = link->l_af_data[nla_type(af_attr)]; in link_msg_parser()
596 err = af_ops->ao_parse_af(link, af_attr, af_data); in link_msg_parser()
602 link->ce_mask |= LINK_ATTR_AF_SPEC; in link_msg_parser()
606 link->l_promiscuity = nla_get_u32(tb[IFLA_PROMISCUITY]); in link_msg_parser()
607 link->ce_mask |= LINK_ATTR_PROMISCUITY; in link_msg_parser()
611 link->l_num_tx_queues = nla_get_u32(tb[IFLA_NUM_TX_QUEUES]); in link_msg_parser()
612 link->ce_mask |= LINK_ATTR_NUM_TX_QUEUES; in link_msg_parser()
616 link->l_num_rx_queues = nla_get_u32(tb[IFLA_NUM_RX_QUEUES]); in link_msg_parser()
617 link->ce_mask |= LINK_ATTR_NUM_RX_QUEUES; in link_msg_parser()
621 link->l_group = nla_get_u32(tb[IFLA_GROUP]); in link_msg_parser()
622 link->ce_mask |= LINK_ATTR_GROUP; in link_msg_parser()
626 link->l_phys_port_id = nl_data_alloc_attr(tb[IFLA_PHYS_PORT_ID]); in link_msg_parser()
627 if (link->l_phys_port_id == NULL) { in link_msg_parser()
631 link->ce_mask |= LINK_ATTR_PHYS_PORT_ID; in link_msg_parser()
634 err = pp->pp_cb((struct nl_object *) link, pp); in link_msg_parser()
637 rtnl_link_put(link); in link_msg_parser()
652 struct rtnl_link *link = (struct rtnl_link *) obj; in link_dump_line() local
660 nl_dump_line(p, "%s %s ", link->l_name, in link_dump_line()
661 nl_llproto2str(link->l_arptype, buf, sizeof(buf))); in link_dump_line()
663 if (link->l_addr && !nl_addr_iszero(link->l_addr)) in link_dump_line()
664 nl_dump(p, "%s ", nl_addr2str(link->l_addr, buf, sizeof(buf))); in link_dump_line()
666 if (link->ce_mask & LINK_ATTR_MASTER) { in link_dump_line()
668 struct rtnl_link *master = rtnl_link_get(cache, link->l_master); in link_dump_line()
673 nl_dump(p, "master %d ", link->l_master); in link_dump_line()
676 rtnl_link_flags2str(link->l_flags, buf, sizeof(buf)); in link_dump_line()
680 if (link->ce_mask & LINK_ATTR_LINK) { in link_dump_line()
682 struct rtnl_link *ll = rtnl_link_get(cache, link->l_link); in link_dump_line()
687 nl_dump(p, "slave-of %d ", link->l_link); in link_dump_line()
690 if (link->ce_mask & LINK_ATTR_GROUP) in link_dump_line()
691 nl_dump(p, "group %u ", link->l_group); in link_dump_line()
693 if (link->l_info_ops && link->l_info_ops->io_dump[NL_DUMP_LINE]) in link_dump_line()
694 link->l_info_ops->io_dump[NL_DUMP_LINE](link, p); in link_dump_line()
696 do_foreach_af(link, af_dump_line, p); in link_dump_line()
706 struct rtnl_link *link = (struct rtnl_link *) obj; in link_dump_details() local
711 nl_dump_line(p, " mtu %u ", link->l_mtu); in link_dump_details()
712 nl_dump(p, "txqlen %u weight %u ", link->l_txqlen, link->l_weight); in link_dump_details()
714 if (link->ce_mask & LINK_ATTR_QDISC) in link_dump_details()
715 nl_dump(p, "qdisc %s ", link->l_qdisc); in link_dump_details()
717 if (link->ce_mask & LINK_ATTR_MAP && link->l_map.lm_irq) in link_dump_details()
718 nl_dump(p, "irq %u ", link->l_map.lm_irq); in link_dump_details()
720 if (link->ce_mask & LINK_ATTR_IFINDEX) in link_dump_details()
721 nl_dump(p, "index %u ", link->l_index); in link_dump_details()
723 if (link->ce_mask & LINK_ATTR_PROMISCUITY && link->l_promiscuity > 0) in link_dump_details()
724 nl_dump(p, "promisc-mode (%u users) ", link->l_promiscuity); in link_dump_details()
728 if (link->ce_mask & LINK_ATTR_IFALIAS) in link_dump_details()
729 nl_dump_line(p, " alias %s\n", link->l_ifalias); in link_dump_details()
733 if (link->ce_mask & LINK_ATTR_NUM_TX_QUEUES) in link_dump_details()
734 nl_dump(p, "txq %u ", link->l_num_tx_queues); in link_dump_details()
736 if (link->ce_mask & LINK_ATTR_NUM_RX_QUEUES) in link_dump_details()
737 nl_dump(p, "rxq %u ", link->l_num_rx_queues); in link_dump_details()
739 if (link->ce_mask & LINK_ATTR_BRD) in link_dump_details()
740 nl_dump(p, "brd %s ", nl_addr2str(link->l_bcast, buf, in link_dump_details()
743 if ((link->ce_mask & LINK_ATTR_OPERSTATE) && in link_dump_details()
744 link->l_operstate != IF_OPER_UNKNOWN) { in link_dump_details()
745 rtnl_link_operstate2str(link->l_operstate, buf, sizeof(buf)); in link_dump_details()
749 if (link->ce_mask & LINK_ATTR_NUM_VF) in link_dump_details()
750 nl_dump(p, "num-vf %u ", link->l_num_vf); in link_dump_details()
753 rtnl_link_mode2str(link->l_linkmode, buf, sizeof(buf))); in link_dump_details()
756 rtnl_link_carrier2str(link->l_carrier, buf, sizeof(buf))); in link_dump_details()
760 if (link->l_info_ops && link->l_info_ops->io_dump[NL_DUMP_DETAILS]) in link_dump_details()
761 link->l_info_ops->io_dump[NL_DUMP_DETAILS](link, p); in link_dump_details()
763 do_foreach_af(link, af_dump_details, p); in link_dump_details()
768 struct rtnl_link *link = (struct rtnl_link *) obj; in link_dump_stats() local
777 res = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_RX_BYTES], &unit); in link_dump_stats()
783 link->l_stats[RTNL_LINK_RX_PACKETS], in link_dump_stats()
784 link->l_stats[RTNL_LINK_RX_ERRORS], in link_dump_stats()
785 link->l_stats[RTNL_LINK_RX_DROPPED], in link_dump_stats()
786 link->l_stats[RTNL_LINK_RX_FIFO_ERR], in link_dump_stats()
787 link->l_stats[RTNL_LINK_RX_COMPRESSED]); in link_dump_stats()
789 res = nl_cancel_down_bytes(link->l_stats[RTNL_LINK_TX_BYTES], &unit); in link_dump_stats()
795 link->l_stats[RTNL_LINK_TX_PACKETS], in link_dump_stats()
796 link->l_stats[RTNL_LINK_TX_ERRORS], in link_dump_stats()
797 link->l_stats[RTNL_LINK_TX_DROPPED], in link_dump_stats()
798 link->l_stats[RTNL_LINK_TX_FIFO_ERR], in link_dump_stats()
799 link->l_stats[RTNL_LINK_TX_COMPRESSED]); in link_dump_stats()
807 link->l_stats[RTNL_LINK_RX_LEN_ERR], in link_dump_stats()
808 link->l_stats[RTNL_LINK_RX_OVER_ERR], in link_dump_stats()
809 link->l_stats[RTNL_LINK_RX_CRC_ERR], in link_dump_stats()
810 link->l_stats[RTNL_LINK_RX_FRAME_ERR], in link_dump_stats()
811 link->l_stats[RTNL_LINK_RX_MISSED_ERR], in link_dump_stats()
812 link->l_stats[RTNL_LINK_MULTICAST]); in link_dump_stats()
819 link->l_stats[RTNL_LINK_TX_ABORT_ERR], in link_dump_stats()
820 link->l_stats[RTNL_LINK_TX_CARRIER_ERR], in link_dump_stats()
821 link->l_stats[RTNL_LINK_TX_HBEAT_ERR], in link_dump_stats()
822 link->l_stats[RTNL_LINK_TX_WIN_ERR], in link_dump_stats()
823 link->l_stats[RTNL_LINK_COLLISIONS]); in link_dump_stats()
825 if (link->l_info_ops && link->l_info_ops->io_dump[NL_DUMP_STATS]) in link_dump_stats()
826 link->l_info_ops->io_dump[NL_DUMP_STATS](link, p); in link_dump_stats()
828 do_foreach_af(link, af_dump_stats, p); in link_dump_stats()
881 struct rtnl_link *link = (struct rtnl_link *) obj; in link_keygen() local
889 lkey.l_index = link->l_index; in link_keygen()
890 lkey.l_family = link->l_family; in link_keygen()
895 link, lkey.l_index, lkey.l_family, lkey_sz, *hashkey); in link_keygen()
955 __ADD(LINK_ATTR_LINK, link)
1055 struct rtnl_link *link; in rtnl_link_get() local
1060 nl_list_for_each_entry(link, &cache->c_items, ce_list) { in rtnl_link_get()
1061 if (link->l_index == ifindex) { in rtnl_link_get()
1062 nl_object_get((struct nl_object *) link); in rtnl_link_get()
1063 return link; in rtnl_link_get()
1088 struct rtnl_link *link; in rtnl_link_get_by_name() local
1093 nl_list_for_each_entry(link, &cache->c_items, ce_list) { in rtnl_link_get_by_name()
1094 if (!strcmp(name, link->l_name)) { in rtnl_link_get_by_name()
1095 nl_object_get((struct nl_object *) link); in rtnl_link_get_by_name()
1096 return link; in rtnl_link_get_by_name()
1211 struct rtnl_link *link = rtnl_link_get(cache, ifindex); in rtnl_link_i2name() local
1213 if (link) { in rtnl_link_i2name()
1214 strncpy(dst, link->l_name, len - 1); in rtnl_link_i2name()
1215 rtnl_link_put(link); in rtnl_link_i2name()
1234 struct rtnl_link *link; in rtnl_link_name2i() local
1236 link = rtnl_link_get_by_name(cache, name); in rtnl_link_name2i()
1237 if (link) { in rtnl_link_name2i()
1238 ifindex = link->l_index; in rtnl_link_name2i()
1239 rtnl_link_put(link); in rtnl_link_name2i()
1247 int rtnl_link_fill_info(struct nl_msg *msg, struct rtnl_link *link) in rtnl_link_fill_info() argument
1249 if (link->ce_mask & LINK_ATTR_ADDR) in rtnl_link_fill_info()
1250 NLA_PUT_ADDR(msg, IFLA_ADDRESS, link->l_addr); in rtnl_link_fill_info()
1252 if (link->ce_mask & LINK_ATTR_BRD) in rtnl_link_fill_info()
1253 NLA_PUT_ADDR(msg, IFLA_BROADCAST, link->l_bcast); in rtnl_link_fill_info()
1255 if (link->ce_mask & LINK_ATTR_MTU) in rtnl_link_fill_info()
1256 NLA_PUT_U32(msg, IFLA_MTU, link->l_mtu); in rtnl_link_fill_info()
1258 if (link->ce_mask & LINK_ATTR_TXQLEN) in rtnl_link_fill_info()
1259 NLA_PUT_U32(msg, IFLA_TXQLEN, link->l_txqlen); in rtnl_link_fill_info()
1261 if (link->ce_mask & LINK_ATTR_WEIGHT) in rtnl_link_fill_info()
1262 NLA_PUT_U32(msg, IFLA_WEIGHT, link->l_weight); in rtnl_link_fill_info()
1264 if (link->ce_mask & LINK_ATTR_IFNAME) in rtnl_link_fill_info()
1265 NLA_PUT_STRING(msg, IFLA_IFNAME, link->l_name); in rtnl_link_fill_info()
1267 if (link->ce_mask & LINK_ATTR_OPERSTATE) in rtnl_link_fill_info()
1268 NLA_PUT_U8(msg, IFLA_OPERSTATE, link->l_operstate); in rtnl_link_fill_info()
1270 if (link->ce_mask & LINK_ATTR_CARRIER) in rtnl_link_fill_info()
1271 NLA_PUT_U8(msg, IFLA_CARRIER, link->l_carrier); in rtnl_link_fill_info()
1273 if (link->ce_mask & LINK_ATTR_LINKMODE) in rtnl_link_fill_info()
1274 NLA_PUT_U8(msg, IFLA_LINKMODE, link->l_linkmode); in rtnl_link_fill_info()
1276 if (link->ce_mask & LINK_ATTR_IFALIAS) in rtnl_link_fill_info()
1277 NLA_PUT_STRING(msg, IFLA_IFALIAS, link->l_ifalias); in rtnl_link_fill_info()
1279 if (link->ce_mask & LINK_ATTR_LINK) in rtnl_link_fill_info()
1280 NLA_PUT_U32(msg, IFLA_LINK, link->l_link); in rtnl_link_fill_info()
1282 if (link->ce_mask & LINK_ATTR_MASTER) in rtnl_link_fill_info()
1283 NLA_PUT_U32(msg, IFLA_MASTER, link->l_master); in rtnl_link_fill_info()
1285 if (link->ce_mask & LINK_ATTR_NUM_TX_QUEUES) in rtnl_link_fill_info()
1286 NLA_PUT_U32(msg, IFLA_NUM_TX_QUEUES, link->l_num_tx_queues); in rtnl_link_fill_info()
1288 if (link->ce_mask & LINK_ATTR_NUM_RX_QUEUES) in rtnl_link_fill_info()
1289 NLA_PUT_U32(msg, IFLA_NUM_RX_QUEUES, link->l_num_rx_queues); in rtnl_link_fill_info()
1291 if (link->ce_mask & LINK_ATTR_NS_FD) in rtnl_link_fill_info()
1292 NLA_PUT_U32(msg, IFLA_NET_NS_FD, link->l_ns_fd); in rtnl_link_fill_info()
1294 if (link->ce_mask & LINK_ATTR_NS_PID) in rtnl_link_fill_info()
1295 NLA_PUT_U32(msg, IFLA_NET_NS_PID, link->l_ns_pid); in rtnl_link_fill_info()
1304 struct rtnl_link *link, int flags, struct nl_msg **result) in build_link_msg() argument
1316 if (rtnl_link_fill_info(msg, link)) in build_link_msg()
1319 if (link->ce_mask & LINK_ATTR_GROUP) in build_link_msg()
1320 NLA_PUT_U32(msg, IFLA_GROUP, link->l_group); in build_link_msg()
1322 if (link->ce_mask & LINK_ATTR_LINKINFO) { in build_link_msg()
1328 NLA_PUT_STRING(msg, IFLA_INFO_KIND, link->l_info_kind); in build_link_msg()
1330 if (link->l_info_ops) { in build_link_msg()
1331 if (link->l_info_ops->io_put_attrs && in build_link_msg()
1332 link->l_info_ops->io_put_attrs(msg, link) < 0) in build_link_msg()
1342 if (do_foreach_af(link, af_fill, msg) < 0) in build_link_msg()
1376 int rtnl_link_build_add_request(struct rtnl_link *link, int flags, in rtnl_link_build_add_request() argument
1380 .ifi_family = link->l_family, in rtnl_link_build_add_request()
1381 .ifi_index = link->l_index, in rtnl_link_build_add_request()
1382 .ifi_flags = link->l_flags, in rtnl_link_build_add_request()
1385 return build_link_msg(RTM_NEWLINK, &ifi, link, flags, result); in rtnl_link_build_add_request()
1405 int rtnl_link_add(struct nl_sock *sk, struct rtnl_link *link, int flags) in rtnl_link_add() argument
1410 err = rtnl_link_build_add_request(link, flags, &msg); in rtnl_link_add()
1550 int rtnl_link_build_delete_request(const struct rtnl_link *link, in rtnl_link_build_delete_request() argument
1555 .ifi_index = link->l_index, in rtnl_link_build_delete_request()
1558 if (!(link->ce_mask & (LINK_ATTR_IFINDEX | LINK_ATTR_IFNAME))) { in rtnl_link_build_delete_request()
1569 if (link->ce_mask & LINK_ATTR_IFNAME) in rtnl_link_build_delete_request()
1570 NLA_PUT_STRING(msg, IFLA_IFNAME, link->l_name); in rtnl_link_build_delete_request()
1604 int rtnl_link_delete(struct nl_sock *sk, const struct rtnl_link *link) in rtnl_link_delete() argument
1609 if ((err = rtnl_link_build_delete_request(link, &msg)) < 0) in rtnl_link_delete()
1637 void rtnl_link_put(struct rtnl_link *link) in rtnl_link_put() argument
1639 nl_object_put((struct nl_object *) link); in rtnl_link_put()
1656 void rtnl_link_set_name(struct rtnl_link *link, const char *name) in rtnl_link_set_name() argument
1658 strncpy(link->l_name, name, sizeof(link->l_name) - 1); in rtnl_link_set_name()
1659 link->ce_mask |= LINK_ATTR_IFNAME; in rtnl_link_set_name()
1670 char *rtnl_link_get_name(struct rtnl_link *link) in rtnl_link_get_name() argument
1672 return link->ce_mask & LINK_ATTR_IFNAME ? link->l_name : NULL; in rtnl_link_get_name()
1680 void rtnl_link_set_group(struct rtnl_link *link, uint32_t group) in rtnl_link_set_group() argument
1682 link->l_group = group; in rtnl_link_set_group()
1683 link->ce_mask |= LINK_ATTR_GROUP; in rtnl_link_set_group()
1692 uint32_t rtnl_link_get_group(struct rtnl_link *link) in rtnl_link_get_group() argument
1694 return link->l_group; in rtnl_link_get_group()
1697 static inline void __assign_addr(struct rtnl_link *link, struct nl_addr **pos, in __assign_addr() argument
1706 link->ce_mask |= flag; in __assign_addr()
1720 void rtnl_link_set_addr(struct rtnl_link *link, struct nl_addr *addr) in rtnl_link_set_addr() argument
1722 __assign_addr(link, &link->l_addr, addr, LINK_ATTR_ADDR); in rtnl_link_set_addr()
1734 struct nl_addr *rtnl_link_get_addr(struct rtnl_link *link) in rtnl_link_get_addr() argument
1736 return link->ce_mask & LINK_ATTR_ADDR ? link->l_addr : NULL; in rtnl_link_get_addr()
1751 void rtnl_link_set_broadcast(struct rtnl_link *link, struct nl_addr *addr) in rtnl_link_set_broadcast() argument
1753 __assign_addr(link, &link->l_bcast, addr, LINK_ATTR_BRD); in rtnl_link_set_broadcast()
1765 struct nl_addr *rtnl_link_get_broadcast(struct rtnl_link *link) in rtnl_link_get_broadcast() argument
1767 return link->ce_mask & LINK_ATTR_BRD ? link->l_bcast : NULL; in rtnl_link_get_broadcast()
1778 void rtnl_link_set_flags(struct rtnl_link *link, unsigned int flags) in rtnl_link_set_flags() argument
1780 link->l_flag_mask |= flags; in rtnl_link_set_flags()
1781 link->l_flags |= flags; in rtnl_link_set_flags()
1782 link->ce_mask |= LINK_ATTR_FLAGS; in rtnl_link_set_flags()
1793 void rtnl_link_unset_flags(struct rtnl_link *link, unsigned int flags) in rtnl_link_unset_flags() argument
1795 link->l_flag_mask |= flags; in rtnl_link_unset_flags()
1796 link->l_flags &= ~flags; in rtnl_link_unset_flags()
1797 link->ce_mask |= LINK_ATTR_FLAGS; in rtnl_link_unset_flags()
1809 unsigned int rtnl_link_get_flags(struct rtnl_link *link) in rtnl_link_get_flags() argument
1811 return link->l_flags; in rtnl_link_get_flags()
1819 void rtnl_link_set_family(struct rtnl_link *link, int family) in rtnl_link_set_family() argument
1821 link->l_family = family; in rtnl_link_set_family()
1822 link->ce_mask |= LINK_ATTR_FAMILY; in rtnl_link_set_family()
1824 if (link->l_af_ops) { in rtnl_link_set_family()
1825 af_free(link, link->l_af_ops, in rtnl_link_set_family()
1826 link->l_af_data[link->l_af_ops->ao_family], NULL); in rtnl_link_set_family()
1827 link->l_af_data[link->l_af_ops->ao_family] = NULL; in rtnl_link_set_family()
1830 link->l_af_ops = af_lookup_and_alloc(link, family); in rtnl_link_set_family()
1840 int rtnl_link_get_family(struct rtnl_link *link) in rtnl_link_get_family() argument
1842 return link->ce_mask & LINK_ATTR_FAMILY ? link->l_family : AF_UNSPEC; in rtnl_link_get_family()
1854 void rtnl_link_set_arptype(struct rtnl_link *link, unsigned int arptype) in rtnl_link_set_arptype() argument
1856 link->l_arptype = arptype; in rtnl_link_set_arptype()
1857 link->ce_mask |= LINK_ATTR_ARPTYPE; in rtnl_link_set_arptype()
1868 unsigned int rtnl_link_get_arptype(struct rtnl_link *link) in rtnl_link_get_arptype() argument
1870 if (link->ce_mask & LINK_ATTR_ARPTYPE) in rtnl_link_get_arptype()
1871 return link->l_arptype; in rtnl_link_get_arptype()
1884 void rtnl_link_set_ifindex(struct rtnl_link *link, int ifindex) in rtnl_link_set_ifindex() argument
1886 link->l_index = ifindex; in rtnl_link_set_ifindex()
1887 link->ce_mask |= LINK_ATTR_IFINDEX; in rtnl_link_set_ifindex()
1899 int rtnl_link_get_ifindex(struct rtnl_link *link) in rtnl_link_get_ifindex() argument
1901 return link->l_index; in rtnl_link_get_ifindex()
1912 void rtnl_link_set_mtu(struct rtnl_link *link, unsigned int mtu) in rtnl_link_set_mtu() argument
1914 link->l_mtu = mtu; in rtnl_link_set_mtu()
1915 link->ce_mask |= LINK_ATTR_MTU; in rtnl_link_set_mtu()
1926 unsigned int rtnl_link_get_mtu(struct rtnl_link *link) in rtnl_link_get_mtu() argument
1928 return link->l_mtu; in rtnl_link_get_mtu()
1941 void rtnl_link_set_txqlen(struct rtnl_link *link, unsigned int txqlen) in rtnl_link_set_txqlen() argument
1943 link->l_txqlen = txqlen; in rtnl_link_set_txqlen()
1944 link->ce_mask |= LINK_ATTR_TXQLEN; in rtnl_link_set_txqlen()
1957 unsigned int rtnl_link_get_txqlen(struct rtnl_link *link) in rtnl_link_get_txqlen() argument
1959 return link->ce_mask & LINK_ATTR_TXQLEN ? link->l_txqlen : 0; in rtnl_link_get_txqlen()
1962 void rtnl_link_set_link(struct rtnl_link *link, int ifindex) in rtnl_link_set_link() argument
1964 link->l_link = ifindex; in rtnl_link_set_link()
1965 link->ce_mask |= LINK_ATTR_LINK; in rtnl_link_set_link()
1968 int rtnl_link_get_link(struct rtnl_link *link) in rtnl_link_get_link() argument
1970 return link->l_link; in rtnl_link_get_link()
1980 void rtnl_link_set_master(struct rtnl_link *link, int ifindex) in rtnl_link_set_master() argument
1982 link->l_master = ifindex; in rtnl_link_set_master()
1983 link->ce_mask |= LINK_ATTR_MASTER; in rtnl_link_set_master()
1993 int rtnl_link_get_master(struct rtnl_link *link) in rtnl_link_get_master() argument
1995 return link->l_master; in rtnl_link_get_master()
2005 void rtnl_link_set_carrier(struct rtnl_link *link, uint8_t status) in rtnl_link_set_carrier() argument
2007 link->l_carrier = status; in rtnl_link_set_carrier()
2008 link->ce_mask |= LINK_ATTR_CARRIER; in rtnl_link_set_carrier()
2018 uint8_t rtnl_link_get_carrier(struct rtnl_link *link) in rtnl_link_get_carrier() argument
2020 return link->l_carrier; in rtnl_link_get_carrier()
2031 void rtnl_link_set_operstate(struct rtnl_link *link, uint8_t status) in rtnl_link_set_operstate() argument
2033 link->l_operstate = status; in rtnl_link_set_operstate()
2034 link->ce_mask |= LINK_ATTR_OPERSTATE; in rtnl_link_set_operstate()
2045 uint8_t rtnl_link_get_operstate(struct rtnl_link *link) in rtnl_link_get_operstate() argument
2047 return link->l_operstate; in rtnl_link_get_operstate()
2058 void rtnl_link_set_linkmode(struct rtnl_link *link, uint8_t mode) in rtnl_link_set_linkmode() argument
2060 link->l_linkmode = mode; in rtnl_link_set_linkmode()
2061 link->ce_mask |= LINK_ATTR_LINKMODE; in rtnl_link_set_linkmode()
2072 uint8_t rtnl_link_get_linkmode(struct rtnl_link *link) in rtnl_link_get_linkmode() argument
2074 return link->l_linkmode; in rtnl_link_get_linkmode()
2085 const char *rtnl_link_get_ifalias(struct rtnl_link *link) in rtnl_link_get_ifalias() argument
2087 return link->l_ifalias; in rtnl_link_get_ifalias()
2102 void rtnl_link_set_ifalias(struct rtnl_link *link, const char *alias) in rtnl_link_set_ifalias() argument
2104 free(link->l_ifalias); in rtnl_link_set_ifalias()
2107 link->l_ifalias = strdup(alias); in rtnl_link_set_ifalias()
2108 link->ce_mask |= LINK_ATTR_IFALIAS; in rtnl_link_set_ifalias()
2110 link->l_ifalias = NULL; in rtnl_link_set_ifalias()
2111 link->ce_mask &= ~LINK_ATTR_IFALIAS; in rtnl_link_set_ifalias()
2128 void rtnl_link_set_qdisc(struct rtnl_link *link, const char *name) in rtnl_link_set_qdisc() argument
2130 strncpy(link->l_qdisc, name, sizeof(link->l_qdisc) - 1); in rtnl_link_set_qdisc()
2131 link->ce_mask |= LINK_ATTR_QDISC; in rtnl_link_set_qdisc()
2142 char *rtnl_link_get_qdisc(struct rtnl_link *link) in rtnl_link_get_qdisc() argument
2144 return link->ce_mask & LINK_ATTR_QDISC ? link->l_qdisc : NULL; in rtnl_link_get_qdisc()
2155 int rtnl_link_get_num_vf(struct rtnl_link *link, uint32_t *num_vf) in rtnl_link_get_num_vf() argument
2157 if (link->ce_mask & LINK_ATTR_NUM_VF) { in rtnl_link_get_num_vf()
2158 *num_vf = link->l_num_vf; in rtnl_link_get_num_vf()
2171 uint64_t rtnl_link_get_stat(struct rtnl_link *link, rtnl_link_stat_id_t id) in rtnl_link_get_stat() argument
2176 return link->l_stats[id]; in rtnl_link_get_stat()
2190 int rtnl_link_set_stat(struct rtnl_link *link, rtnl_link_stat_id_t id, in rtnl_link_set_stat() argument
2196 link->l_stats[id] = value; in rtnl_link_set_stat()
2213 int rtnl_link_set_type(struct rtnl_link *link, const char *type) in rtnl_link_set_type() argument
2219 free(link->l_info_kind); in rtnl_link_set_type()
2220 link->ce_mask &= ~LINK_ATTR_LINKINFO; in rtnl_link_set_type()
2221 if (link->l_info_ops) in rtnl_link_set_type()
2222 release_link_info(link); in rtnl_link_set_type()
2233 if (io->io_alloc && (err = io->io_alloc(link)) < 0) in rtnl_link_set_type()
2236 link->l_info_ops = io; in rtnl_link_set_type()
2239 link->l_info_kind = kind; in rtnl_link_set_type()
2240 link->ce_mask |= LINK_ATTR_LINKINFO; in rtnl_link_set_type()
2256 char *rtnl_link_get_type(struct rtnl_link *link) in rtnl_link_get_type() argument
2258 return link->l_info_kind; in rtnl_link_get_type()
2270 void rtnl_link_set_promiscuity(struct rtnl_link *link, uint32_t count) in rtnl_link_set_promiscuity() argument
2272 link->l_promiscuity = count; in rtnl_link_set_promiscuity()
2273 link->ce_mask |= LINK_ATTR_PROMISCUITY; in rtnl_link_set_promiscuity()
2283 uint32_t rtnl_link_get_promiscuity(struct rtnl_link *link) in rtnl_link_get_promiscuity() argument
2285 return link->l_promiscuity; in rtnl_link_get_promiscuity()
2302 void rtnl_link_set_num_tx_queues(struct rtnl_link *link, uint32_t nqueues) in rtnl_link_set_num_tx_queues() argument
2304 link->l_num_tx_queues = nqueues; in rtnl_link_set_num_tx_queues()
2305 link->ce_mask |= LINK_ATTR_NUM_TX_QUEUES; in rtnl_link_set_num_tx_queues()
2314 uint32_t rtnl_link_get_num_tx_queues(struct rtnl_link *link) in rtnl_link_get_num_tx_queues() argument
2316 return link->l_num_tx_queues; in rtnl_link_get_num_tx_queues()
2333 void rtnl_link_set_num_rx_queues(struct rtnl_link *link, uint32_t nqueues) in rtnl_link_set_num_rx_queues() argument
2335 link->l_num_rx_queues = nqueues; in rtnl_link_set_num_rx_queues()
2336 link->ce_mask |= LINK_ATTR_NUM_RX_QUEUES; in rtnl_link_set_num_rx_queues()
2345 uint32_t rtnl_link_get_num_rx_queues(struct rtnl_link *link) in rtnl_link_get_num_rx_queues() argument
2347 return link->l_num_rx_queues; in rtnl_link_get_num_rx_queues()
2356 struct nl_data *rtnl_link_get_phys_port_id(struct rtnl_link *link) in rtnl_link_get_phys_port_id() argument
2358 return link->l_phys_port_id; in rtnl_link_get_phys_port_id()
2361 void rtnl_link_set_ns_fd(struct rtnl_link *link, int fd) in rtnl_link_set_ns_fd() argument
2363 link->l_ns_fd = fd; in rtnl_link_set_ns_fd()
2364 link->ce_mask |= LINK_ATTR_NS_FD; in rtnl_link_set_ns_fd()
2367 int rtnl_link_get_ns_fd(struct rtnl_link *link) in rtnl_link_get_ns_fd() argument
2369 return link->l_ns_fd; in rtnl_link_get_ns_fd()
2372 void rtnl_link_set_ns_pid(struct rtnl_link *link, pid_t pid) in rtnl_link_set_ns_pid() argument
2374 link->l_ns_pid = pid; in rtnl_link_set_ns_pid()
2375 link->ce_mask |= LINK_ATTR_NS_PID; in rtnl_link_set_ns_pid()
2378 pid_t rtnl_link_get_ns_pid(struct rtnl_link *link) in rtnl_link_get_ns_pid() argument
2380 return link->l_ns_pid; in rtnl_link_get_ns_pid()
2405 struct rtnl_link *link; in rtnl_link_enslave_ifindex() local
2408 if (!(link = rtnl_link_alloc())) in rtnl_link_enslave_ifindex()
2411 rtnl_link_set_ifindex(link, slave); in rtnl_link_enslave_ifindex()
2412 rtnl_link_set_master(link, master); in rtnl_link_enslave_ifindex()
2414 if ((err = rtnl_link_change(sock, link, link, 0)) < 0) in rtnl_link_enslave_ifindex()
2417 rtnl_link_put(link); in rtnl_link_enslave_ifindex()
2426 if ((err = rtnl_link_get_kernel(sock, slave, NULL, &link)) < 0) in rtnl_link_enslave_ifindex()
2429 if (rtnl_link_get_master(link) != master) in rtnl_link_enslave_ifindex()
2433 rtnl_link_put(link); in rtnl_link_enslave_ifindex()
2684 int rtnl_link_set_info_type(struct rtnl_link *link, const char *type) in rtnl_link_set_info_type() argument
2686 return rtnl_link_set_type(link, type); in rtnl_link_set_info_type()
2692 char *rtnl_link_get_info_type(struct rtnl_link *link) in rtnl_link_get_info_type() argument
2694 return rtnl_link_get_type(link); in rtnl_link_get_info_type()
2700 void rtnl_link_set_weight(struct rtnl_link *link, unsigned int weight) in rtnl_link_set_weight() argument
2702 link->l_weight = weight; in rtnl_link_set_weight()
2703 link->ce_mask |= LINK_ATTR_WEIGHT; in rtnl_link_set_weight()
2709 unsigned int rtnl_link_get_weight(struct rtnl_link *link) in rtnl_link_get_weight() argument
2711 return link->l_weight; in rtnl_link_get_weight()