static void print_linktype(FILE *fp, struct rtattr *tb) { struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct link_util *lu; char *kind; parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb); if (!linkinfo[IFLA_INFO_KIND]) return; kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]); fprintf(fp, "%s", _SL_); fprintf(fp, " %s ", kind); lu = get_link_kind(kind); if (!lu || !lu->print_opt) return; if (1) { struct rtattr *attr[lu->maxattr+1], **data = NULL; if (linkinfo[IFLA_INFO_DATA]) { parse_rtattr_nested(attr, lu->maxattr, linkinfo[IFLA_INFO_DATA]); data = attr; } lu->print_opt(lu, fp, data); if (linkinfo[IFLA_INFO_XSTATS] && show_stats && lu->print_xstats) lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]); } }
static void print_linktype(FILE *fp, struct rtattr *tb) { struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct link_util *lu; struct link_util *slave_lu; char *kind; char *slave_kind; parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb); if (linkinfo[IFLA_INFO_KIND]) { kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]); fprintf(fp, "%s", _SL_); fprintf(fp, " %s ", kind); lu = get_link_kind(kind); if (lu && lu->print_opt) { struct rtattr *attr[lu->maxattr+1], **data = NULL; if (linkinfo[IFLA_INFO_DATA]) { parse_rtattr_nested(attr, lu->maxattr, linkinfo[IFLA_INFO_DATA]); data = attr; } lu->print_opt(lu, fp, data); if (linkinfo[IFLA_INFO_XSTATS] && show_stats && lu->print_xstats) lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]); } } if (linkinfo[IFLA_INFO_SLAVE_KIND]) { slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]); fprintf(fp, "%s", _SL_); fprintf(fp, " %s_slave ", slave_kind); slave_lu = get_link_slave_kind(slave_kind); if (slave_lu && slave_lu->print_opt) { struct rtattr *attr[slave_lu->maxattr+1], **data = NULL; if (linkinfo[IFLA_INFO_SLAVE_DATA]) { parse_rtattr_nested(attr, slave_lu->maxattr, linkinfo[IFLA_INFO_SLAVE_DATA]); data = attr; } slave_lu->print_opt(slave_lu, fp, data); } } }
static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg) { struct rtattr *tb[TCA_CONNMARK_MAX + 1]; struct tc_connmark *ci; if (arg == NULL) return -1; parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg); if (tb[TCA_CONNMARK_PARMS] == NULL) { fprintf(f, "[NULL connmark parameters]"); return -1; } ci = RTA_DATA(tb[TCA_CONNMARK_PARMS]); fprintf(f, " connmark zone %d\n", ci->zone); fprintf(f, "\t index %d ref %d bind %d", ci->index, ci->refcnt, ci->bindcnt); if (show_stats) { if (tb[TCA_CONNMARK_TM]) { struct tcf_t *tm = RTA_DATA(tb[TCA_CONNMARK_TM]); print_tm(f, tm); } } fprintf(f, "\n"); return 0; }
static int wrr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_OPTIONS-1]; struct wrr_class_opt *copt; struct wrr_gopt *gopt; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_WRR_MAX, opt); if (tb[TCA_WRR_PARAMS]) { copt = RTA_DATA(tb[TCA_WRR_PARAMS]); if (RTA_PAYLOAD(tb[TCA_WRR_PARAMS]) < sizeof(*copt)) return -1; fprintf(f, "quantum %u nfmark %u.", copt->quantum, copt->handle); } if (tb[TCA_WRR_INIT]) { gopt = RTA_DATA(tb[TCA_WRR_INIT]); if (RTA_PAYLOAD(tb[TCA_WRR_INIT]) < sizeof(*gopt)) return -1; fprintf(f, "queues %u", gopt->total_queues); } return 0; }
static int pedit_keys_ex_getattr(struct rtattr *attr, struct m_pedit_key_ex *keys_ex, int n) { struct rtattr *i; int rem = RTA_PAYLOAD(attr); struct rtattr *tb[TCA_PEDIT_KEY_EX_MAX + 1]; struct m_pedit_key_ex *k = keys_ex; for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { if (!n) return -1; if (i->rta_type != TCA_PEDIT_KEY_EX) return -1; parse_rtattr_nested(tb, TCA_PEDIT_KEY_EX_MAX, i); k->htype = rta_getattr_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]); k->cmd = rta_getattr_u16(tb[TCA_PEDIT_KEY_EX_CMD]); k++; n--; } return !!n; }
static void print_vfinfo(FILE *fp, struct rtattr *vfinfo) { struct ifla_vf_mac *vf_mac; struct ifla_vf_vlan *vf_vlan; struct ifla_vf_tx_rate *vf_tx_rate; struct rtattr *vf[IFLA_VF_MAX+1]; SPRINT_BUF(b1); if (vfinfo->rta_type != IFLA_VF_INFO) { fprintf(stderr, "BUG: rta type is %d\n", vfinfo->rta_type); return; } parse_rtattr_nested(vf, IFLA_VF_MAX, vfinfo); vf_mac = RTA_DATA(vf[IFLA_VF_MAC]); vf_vlan = RTA_DATA(vf[IFLA_VF_VLAN]); vf_tx_rate = RTA_DATA(vf[IFLA_VF_TX_RATE]); fprintf(fp, "\n vf %d MAC %s", vf_mac->vf, ll_addr_n2a((unsigned char *)&vf_mac->mac, ETH_ALEN, 0, b1, sizeof(b1))); if (vf_vlan->vlan) fprintf(fp, ", vlan %d", vf_vlan->vlan); if (vf_vlan->qos) fprintf(fp, ", qos %d", vf_vlan->qos); if (vf_tx_rate->rate) fprintf(fp, ", tx rate %d (Mbps)", vf_tx_rate->rate); }
static int basic_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_BASIC_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_BASIC_MAX, opt); if (handle) fprintf(f, "handle 0x%x ", handle); if (tb[TCA_BASIC_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "flowid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1)); } if (tb[TCA_BASIC_EMATCHES]) print_ematch(f, tb[TCA_BASIC_EMATCHES]); if (tb[TCA_BASIC_POLICE]) { fprintf(f, "\n"); tc_print_police(f, tb[TCA_BASIC_POLICE]); } if (tb[TCA_BASIC_ACT]) { tc_print_action(f, tb[TCA_BASIC_ACT]); } return 0; }
static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_FW_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_FW_MAX, opt); if (handle) fprintf(f, "handle 0x%x ", handle); if (tb[TCA_FW_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "classid %s ", sprint_tc_classid(*(__u32*)RTA_DATA(tb[TCA_FW_CLASSID]), b1)); } if (tb[TCA_FW_POLICE]) tc_print_police(f, tb[TCA_FW_POLICE]); if (tb[TCA_FW_INDEV]) { struct rtattr *idev = tb[TCA_FW_INDEV]; fprintf(f, "input dev %s ",(char *)RTA_DATA(idev)); } if (tb[TCA_FW_ACT]) { fprintf(f, "\n"); tc_print_action(f, tb[TCA_FW_ACT]); } return 0; }
static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_RED_STAB+1]; struct tc_red_qopt *qopt; SPRINT_BUF(b1); SPRINT_BUF(b2); SPRINT_BUF(b3); if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_RED_STAB, opt); if (tb[TCA_RED_PARMS] == NULL) return -1; qopt = RTA_DATA(tb[TCA_RED_PARMS]); if (RTA_PAYLOAD(tb[TCA_RED_PARMS]) < sizeof(*qopt)) return -1; fprintf(f, "limit %s min %s max %s ", sprint_size(qopt->limit, b1), sprint_size(qopt->qth_min, b2), sprint_size(qopt->qth_max, b3)); #ifdef TC_RED_ECN if (qopt->flags & TC_RED_ECN) fprintf(f, "ecn "); #endif if (show_details) { fprintf(f, "ewma %u Plog %u Scell_log %u", qopt->Wlog, qopt->Plog, qopt->Scell_log); } return 0; }
static void ipoe_vlan_mon_handler(const struct sockaddr_nl *addr, struct nlmsghdr *h) { struct rtattr *tb[PKT_ATTR_MAX + 1]; struct rtattr *tb2[IPOE_ATTR_MAX + 1]; struct genlmsghdr *ghdr = NLMSG_DATA(h); int len = h->nlmsg_len; struct rtattr *attrs; int i; int ifindex, vid; len -= NLMSG_LENGTH(GENL_HDRLEN); if (len < 0) { log_warn("ipoe: wrong controller message length %d\n", len); return; } attrs = (struct rtattr *)((char *)ghdr + GENL_HDRLEN); parse_rtattr(tb, PKT_ATTR_MAX, attrs, len); for (i = 1; i < PKT_ATTR_MAX; i++) { if (!tb[i]) break; parse_rtattr_nested(tb2, IPOE_ATTR_MAX, tb[i]); if (!tb2[IPOE_ATTR_IFINDEX] || !tb2[IPOE_ATTR_ADDR]) continue; ifindex = *(uint32_t *)(RTA_DATA(tb2[IPOE_ATTR_IFINDEX])); vid = *(uint32_t *)(RTA_DATA(tb2[IPOE_ATTR_ADDR])); ipoe_vlan_notify(ifindex, vid); } }
static int cgroup_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_CGROUP_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt); if (handle) fprintf(f, "handle 0x%x ", handle); if (tb[TCA_CGROUP_EMATCHES]) print_ematch(f, tb[TCA_CGROUP_EMATCHES]); if (tb[TCA_CGROUP_POLICE]) { fprintf(f, "\n"); tc_print_police(f, tb[TCA_CGROUP_POLICE]); } if (tb[TCA_CGROUP_ACT]) tc_print_action(f, tb[TCA_CGROUP_ACT]); return 0; }
static int netlink_extract_vxlan_info(struct rtattr *link_data, struct zebra_l2info_vxlan *vxl_info) { struct rtattr *attr[IFLA_VXLAN_MAX + 1]; vni_t vni_in_msg; struct in_addr vtep_ip_in_msg; memset(vxl_info, 0, sizeof(*vxl_info)); memset(attr, 0, sizeof attr); parse_rtattr_nested(attr, IFLA_VXLAN_MAX, link_data); if (!attr[IFLA_VXLAN_ID]) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "IFLA_VXLAN_ID missing from VXLAN IF message"); return -1; } vni_in_msg = *(vni_t *)RTA_DATA(attr[IFLA_VXLAN_ID]); vxl_info->vni = vni_in_msg; if (!attr[IFLA_VXLAN_LOCAL]) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "IFLA_VXLAN_LOCAL missing from VXLAN IF message"); } else { vtep_ip_in_msg = *(struct in_addr *)RTA_DATA(attr[IFLA_VXLAN_LOCAL]); vxl_info->vtep_ip = vtep_ip_in_msg; } return 0; }
int tc_print_action(FILE * f, const struct rtattr *arg) { int i; struct rtattr *tb[TCA_ACT_MAX_PRIO + 1]; if (arg == NULL) return 0; parse_rtattr_nested(tb, TCA_ACT_MAX_PRIO, arg); if (tab_flush && NULL != tb[0] && NULL == tb[1]) { int ret = tc_print_one_action(f, tb[0]); return ret; } for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { if (tb[i]) { fprintf(f, "\n\taction order %d: ", i + batch_c); if (0 > tc_print_one_action(f, tb[i])) { fprintf(f, "Error printing action\n"); } } } batch_c+=TCA_ACT_MAX_PRIO ; return 0; }
int print_ematch(FILE *fd, const struct rtattr *rta) { struct rtattr *tb[TCA_EMATCH_TREE_MAX+1]; struct tcf_ematch_tree_hdr *hdr; if (parse_rtattr_nested(tb, TCA_EMATCH_TREE_MAX, rta) < 0) return -1; if (tb[TCA_EMATCH_TREE_HDR] == NULL) { fprintf(stderr, "Missing ematch tree header\n"); return -1; } if (tb[TCA_EMATCH_TREE_LIST] == NULL) { fprintf(stderr, "Missing ematch tree list\n"); return -1; } if (RTA_PAYLOAD(tb[TCA_EMATCH_TREE_HDR]) < sizeof(*hdr)) { fprintf(stderr, "Ematch tree header size mismatch\n"); return -1; } hdr = RTA_DATA(tb[TCA_EMATCH_TREE_HDR]); return print_ematch_list(fd, hdr, tb[TCA_EMATCH_TREE_LIST]); }
static int get_ctrl_grp_id(struct rtattr *arg) { struct rtattr *tb[CTRL_ATTR_MCAST_GRP_MAX + 1]; char *name; if (arg == NULL) return -1; /* nested within the CTRL_ATTR_MCAST_GROUPS attribute are the */ /* group name and ID */ parse_rtattr_nested(tb, CTRL_ATTR_MCAST_GRP_MAX, arg); /* if either of the entries needed cannot be found, bail */ if (!tb[CTRL_ATTR_MCAST_GRP_NAME] || !tb[CTRL_ATTR_MCAST_GRP_ID]) return -1; /* get the name of this multicast group we've found */ name = RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_NAME]); /* if it does not match the ACPI event multicast group name, bail */ if (strcmp(name, ACPI_EVENT_MCAST_GROUP_NAME)) return -1; /* At this point, we've found what we were looking for. We now */ /* have the multicast group ID for ACPI events over generic netlink. */ acpi_event_mcast_group_id = *((__u32 *)RTA_DATA(tb[CTRL_ATTR_MCAST_GRP_ID])); return 0; }
static int myred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_MYRED_STAB+1]; struct tc_myred_qopt *qopt; SPRINT_BUF(b1); if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_MYRED_STAB, opt); if (tb[TCA_MYRED_PARMS] == NULL) return -1; qopt = RTA_DATA(tb[TCA_MYRED_PARMS]); if (RTA_PAYLOAD(tb[TCA_MYRED_PARMS]) < sizeof(*qopt)) return -1; fprintf(f, "limit %s", sprint_size(qopt->limit, b1)); #ifdef TC_MYRED_ECN if (qopt->flags & TC_MYRED_ECN) fprintf(f, "ecn "); #endif /*qjl*/ if (show_details) { fprintf(f, "p_init %lf p_min %lf p_max %lf q_min %d q_max %d sampl_period %d", qopt->p_init, qopt->p_min, qopt->p_max, qopt->q_min, qopt->q_max, qopt->sampl_period); } return 0; }
static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_ATM_MAX+1]; char buffer[MAX_ATM_ADDR_LEN+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_ATM_MAX, opt); if (tb[TCA_ATM_ADDR]) { if (RTA_PAYLOAD(tb[TCA_ATM_ADDR]) < sizeof(struct sockaddr_atmpvc)) fprintf(stderr,"ATM: address too short\n"); else { if (atm2text(buffer,MAX_ATM_ADDR_LEN, RTA_DATA(tb[TCA_ATM_ADDR]),A2T_PRETTY | A2T_NAME) < 0) fprintf(stderr,"atm2text error\n"); fprintf(f,"pvc %s ",buffer); } } if (tb[TCA_ATM_HDR]) { int i; const __u8 *hdr = RTA_DATA(tb[TCA_ATM_HDR]); fprintf(f,"hdr"); for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++) fprintf(f,"%c%02x", i ? '.' : ' ', hdr[i]); if (!i) fprintf(f," ."); fprintf(f," "); } if (tb[TCA_ATM_EXCESS]) { __u32 excess; if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS]) < sizeof(excess)) fprintf(stderr,"ATM: excess class ID too short\n"); else { excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]); if (!excess) fprintf(f,"excess clp "); else { char buf[64]; print_tc_classid(buf,sizeof(buf),excess); fprintf(f,"excess %s ",buf); } } } if (tb[TCA_ATM_STATE]) { static const char *map[] = { ATM_VS2TXT_MAP }; int state; if (RTA_PAYLOAD(tb[TCA_ATM_STATE]) < sizeof(state)) fprintf(stderr,"ATM: state field too short\n"); else { state = *(int *) RTA_DATA(tb[TCA_ATM_STATE]); fprintf(f,"%s ",map[state]); } } return 0; }
static int tcindex_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { struct rtattr *tb[TCA_TCINDEX_MAX+1]; if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_TCINDEX_MAX, opt); if (handle != ~0) fprintf(f, "handle 0x%04x ", handle); if (tb[TCA_TCINDEX_HASH]) { __u16 hash; if (RTA_PAYLOAD(tb[TCA_TCINDEX_HASH]) < sizeof(hash)) return -1; hash = rta_getattr_u16(tb[TCA_TCINDEX_HASH]); fprintf(f, "hash %d ", hash); } if (tb[TCA_TCINDEX_MASK]) { __u16 mask; if (RTA_PAYLOAD(tb[TCA_TCINDEX_MASK]) < sizeof(mask)) return -1; mask = rta_getattr_u16(tb[TCA_TCINDEX_MASK]); fprintf(f, "mask 0x%04x ", mask); } if (tb[TCA_TCINDEX_SHIFT]) { int shift; if (RTA_PAYLOAD(tb[TCA_TCINDEX_SHIFT]) < sizeof(shift)) return -1; shift = *(int *) RTA_DATA(tb[TCA_TCINDEX_SHIFT]); fprintf(f, "shift %d ", shift); } if (tb[TCA_TCINDEX_FALL_THROUGH]) { int fall_through; if (RTA_PAYLOAD(tb[TCA_TCINDEX_FALL_THROUGH]) < sizeof(fall_through)) return -1; fall_through = *(int *) RTA_DATA(tb[TCA_TCINDEX_FALL_THROUGH]); fprintf(f, fall_through ? "fall_through " : "pass_on "); } if (tb[TCA_TCINDEX_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "classid %s ", sprint_tc_classid(*(__u32 *) RTA_DATA(tb[TCA_TCINDEX_CLASSID]), b1)); } if (tb[TCA_TCINDEX_POLICE]) { fprintf(f, "\n"); tc_print_police(f, tb[TCA_TCINDEX_POLICE]); } if (tb[TCA_TCINDEX_ACT]) { fprintf(f, "\n"); tc_print_police(f, tb[TCA_TCINDEX_ACT]); } return 0; }
static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_TBF_PTAB+1]; struct tc_tbf_qopt *qopt; double buffer, mtu; double latency; SPRINT_BUF(b1); SPRINT_BUF(b2); if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_TBF_PTAB, opt); if (tb[TCA_TBF_PARMS] == NULL) return -1; qopt = RTA_DATA(tb[TCA_TBF_PARMS]); if (RTA_PAYLOAD(tb[TCA_TBF_PARMS]) < sizeof(*qopt)) return -1; fprintf(f, "rate %s ", sprint_rate(qopt->rate.rate, b1)); buffer = tc_calc_xmitsize(qopt->rate.rate, qopt->buffer); if (show_details) { fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1), 1<<qopt->rate.cell_log, sprint_size(qopt->rate.mpu, b2)); } else { fprintf(f, "burst %s ", sprint_size(buffer, b1)); } if (show_raw) fprintf(f, "[%08x] ", qopt->buffer); if (qopt->peakrate.rate) { fprintf(f, "peakrate %s ", sprint_rate(qopt->peakrate.rate, b1)); if (qopt->mtu || qopt->peakrate.mpu) { mtu = tc_calc_xmitsize(qopt->peakrate.rate, qopt->mtu); if (show_details) { fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1), 1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2)); } else { fprintf(f, "minburst %s ", sprint_size(mtu, b1)); } if (show_raw) fprintf(f, "[%08x] ", qopt->mtu); } } if (show_raw) fprintf(f, "limit %s ", sprint_size(qopt->limit, b1)); latency = TIME_UNITS_PER_SEC*(qopt->limit/(double)qopt->rate.rate) - tc_core_tick2time(qopt->buffer); if (qopt->peakrate.rate) { double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)qopt->peakrate.rate) - tc_core_tick2time(qopt->mtu); if (lat2 > latency) latency = lat2; } fprintf(f, "lat %s ", sprint_time(latency, b1)); return 0; }
static int pie_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_PIE_MAX + 1]; unsigned int limit; unsigned int tupdate; unsigned int target; unsigned int alpha; unsigned int beta; unsigned ecn; unsigned bytemode; SPRINT_BUF(b1); if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_PIE_MAX, opt); if (tb[TCA_PIE_LIMIT] && RTA_PAYLOAD(tb[TCA_PIE_LIMIT]) >= sizeof(__u32)) { limit = rta_getattr_u32(tb[TCA_PIE_LIMIT]); fprintf(f, "limit %up ", limit); } if (tb[TCA_PIE_TARGET] && RTA_PAYLOAD(tb[TCA_PIE_TARGET]) >= sizeof(__u32)) { target = rta_getattr_u32(tb[TCA_PIE_TARGET]); fprintf(f, "target %s ", sprint_time(target, b1)); } if (tb[TCA_PIE_TUPDATE] && RTA_PAYLOAD(tb[TCA_PIE_TUPDATE]) >= sizeof(__u32)) { tupdate = rta_getattr_u32(tb[TCA_PIE_TUPDATE]); fprintf(f, "tupdate %s ", sprint_time(tupdate, b1)); } if (tb[TCA_PIE_ALPHA] && RTA_PAYLOAD(tb[TCA_PIE_ALPHA]) >= sizeof(__u32)) { alpha = rta_getattr_u32(tb[TCA_PIE_ALPHA]); fprintf(f, "alpha %u ", alpha); } if (tb[TCA_PIE_BETA] && RTA_PAYLOAD(tb[TCA_PIE_BETA]) >= sizeof(__u32)) { beta = rta_getattr_u32(tb[TCA_PIE_BETA]); fprintf(f, "beta %u ", beta); } if (tb[TCA_PIE_ECN] && RTA_PAYLOAD(tb[TCA_PIE_ECN]) >= sizeof(__u32)) { ecn = rta_getattr_u32(tb[TCA_PIE_ECN]); if (ecn) fprintf(f, "ecn "); } if (tb[TCA_PIE_BYTEMODE] && RTA_PAYLOAD(tb[TCA_PIE_BYTEMODE]) >= sizeof(__u32)) { bytemode = rta_getattr_u32(tb[TCA_PIE_BYTEMODE]); if (bytemode) fprintf(f, "bytemode "); } return 0; }
static void print_encap_mpls(FILE *fp, struct rtattr *encap) { struct rtattr *tb[MPLS_IPTUNNEL_MAX+1]; parse_rtattr_nested(tb, MPLS_IPTUNNEL_MAX, encap); if (tb[MPLS_IPTUNNEL_DST]) fprintf(fp, " %s ", format_host_rta(AF_MPLS, tb[MPLS_IPTUNNEL_DST])); }
static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id, int startup) { char *name = NULL; struct ifinfomsg *ifi; struct rtattr *tb[IFLA_MAX + 1]; struct interface *ifp; struct rtattr *aftb[IFLA_BRIDGE_MAX + 1]; struct { uint16_t flags; uint16_t vid; } * vinfo; vlanid_t access_vlan; /* Fetch name and ifindex */ ifi = NLMSG_DATA(h); memset(tb, 0, sizeof tb); netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); if (tb[IFLA_IFNAME] == NULL) return -1; name = (char *)RTA_DATA(tb[IFLA_IFNAME]); /* The interface should already be known, if not discard. */ ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ifi->ifi_index); if (!ifp) { zlog_warn("Cannot find bridge IF %s(%u)", name, ifi->ifi_index); return 0; } if (!IS_ZEBRA_IF_VXLAN(ifp)) return 0; /* We are only interested in the access VLAN i.e., AF_SPEC */ if (!tb[IFLA_AF_SPEC]) return 0; /* There is a 1-to-1 mapping of VLAN to VxLAN - hence * only 1 access VLAN is accepted. */ memset(aftb, 0, sizeof aftb); parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]); if (!aftb[IFLA_BRIDGE_VLAN_INFO]) return 0; vinfo = RTA_DATA(aftb[IFLA_BRIDGE_VLAN_INFO]); if (!(vinfo->flags & BRIDGE_VLAN_INFO_PVID)) return 0; access_vlan = (vlanid_t)vinfo->vid; if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Access VLAN %u for VxLAN IF %s(%u)", access_vlan, name, ifi->ifi_index); zebra_l2_vxlanif_update_access_vlan(ifp, access_vlan); return 0; }
static char *parse_link_kind(struct rtattr *tb) { struct rtattr *linkinfo[IFLA_INFO_MAX+1]; parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb); if (linkinfo[IFLA_INFO_KIND]) return RTA_DATA(linkinfo[IFLA_INFO_KIND]); return ""; }
static void print_txsa_stats(const char *prefix, struct rtattr *attr) { struct rtattr *stats[MACSEC_SA_STATS_ATTR_MAX + 1]; if (!attr || show_stats == 0) return; parse_rtattr_nested(stats, MACSEC_SA_STATS_ATTR_MAX + 1, attr); print_stats(prefix, txsa_stats_names, NUM_MACSEC_SA_STATS_ATTR, stats); }
int cthd_nl_wrapper::genl_get_mcast_group_id(struct nlmsghdr *n) { struct rtattr *tb[CTRL_ATTR_MAX + 1]; struct genlmsghdr *ghdr = (struct genlmsghdr *)NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr *attrs; __u32 ctrl_v = 0x1; if (n->nlmsg_type != GENL_ID_CTRL) { fprintf(stderr, "Not a controller message, nlmsg_len=%d " "nlmsg_type=0x%x\n", n->nlmsg_len, n->nlmsg_type); return 0; } if (ghdr->cmd != CTRL_CMD_GETFAMILY && ghdr->cmd != CTRL_CMD_DELFAMILY && ghdr->cmd != CTRL_CMD_NEWFAMILY && ghdr->cmd != CTRL_CMD_NEWMCAST_GRP && ghdr->cmd != CTRL_CMD_DELMCAST_GRP) { fprintf(stderr, "Unkown controller command %d\n", ghdr->cmd); return 0; } len -= NLMSG_LENGTH(GENL_HDRLEN); if (len < 0) { fprintf(stderr, "wrong controller message len %d\n", len); return -1; } attrs = (struct rtattr *)((char *)ghdr + GENL_HDRLEN); parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); if (tb[CTRL_ATTR_FAMILY_ID]) acpi_event_family_id = *((__u32 *)RTA_DATA(tb[CTRL_ATTR_FAMILY_ID])); if (tb[CTRL_ATTR_MCAST_GROUPS]) { struct rtattr *tb2[GENL_MAX_FAM_GRPS + 1]; int i; parse_rtattr_nested(tb2, GENL_MAX_FAM_GRPS, tb[CTRL_ATTR_MCAST_GROUPS]); for (i = 0; i < GENL_MAX_FAM_GRPS; i++) if (tb2[i]) if (!get_ctrl_grp_id(tb2[i])) return 0; } return -1; }
static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_GRED_STAB+1]; struct tc_gred_qopt *qopt; int i; SPRINT_BUF(b1); SPRINT_BUF(b2); SPRINT_BUF(b3); SPRINT_BUF(b4); SPRINT_BUF(b5); if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_GRED_STAB, opt); if (tb[TCA_GRED_PARMS] == NULL) return -1; qopt = RTA_DATA(tb[TCA_GRED_PARMS]); if (RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) { fprintf(f,"\n GRED received message smaller than expected\n"); return -1; } /* Bad hack! should really return a proper message as shown above*/ for (i=0;i<MAX_DPs;i++, qopt++) { if (qopt->DP >= MAX_DPs) continue; fprintf(f, "\n DP:%d (prio %d) Average Queue %s Measured " "Queue %s ", qopt->DP, qopt->prio, sprint_size(qopt->qave, b4), sprint_size(qopt->backlog, b5)); fprintf(f, "\n\t Packet drops: %d (forced %d early %d) ", qopt->forced+qopt->early, qopt->forced, qopt->early); fprintf(f, "\n\t Packet totals: %u (bytes %u) ", qopt->packets, qopt->bytesin); if (show_details) fprintf(f, "\n limit %s min %s max %s ", sprint_size(qopt->limit, b1), sprint_size(qopt->qth_min, b2), sprint_size(qopt->qth_max, b3)); fprintf(f, "ewma %u Plog %u Scell_log %u", qopt->Wlog, qopt->Plog, qopt->Scell_log); } return 0; }
static int netlink_extract_bridge_info(struct rtattr *link_data, struct zebra_l2info_bridge *bridge_info) { struct rtattr *attr[IFLA_BR_MAX + 1]; memset(bridge_info, 0, sizeof(*bridge_info)); memset(attr, 0, sizeof attr); parse_rtattr_nested(attr, IFLA_BR_MAX, link_data); if (attr[IFLA_BR_VLAN_FILTERING]) bridge_info->vlan_aware = *(uint8_t *)RTA_DATA(attr[IFLA_BR_VLAN_FILTERING]); return 0; }
int print_police(struct action_util *a, FILE *f, struct rtattr *arg) { SPRINT_BUF(b1); SPRINT_BUF(b2); struct tc_police *p; struct rtattr *tb[TCA_POLICE_MAX+1]; unsigned buffer; unsigned int linklayer; if (arg == NULL) return 0; parse_rtattr_nested(tb, TCA_POLICE_MAX, arg); if (tb[TCA_POLICE_TBF] == NULL) { fprintf(f, "[NULL police tbf]"); return 0; } #ifndef STOOPID_8BYTE if (RTA_PAYLOAD(tb[TCA_POLICE_TBF]) < sizeof(*p)) { fprintf(f, "[truncated police tbf]"); return -1; } #endif p = RTA_DATA(tb[TCA_POLICE_TBF]); fprintf(f, " police 0x%x ", p->index); fprintf(f, "rate %s ", sprint_rate(p->rate.rate, b1)); buffer = tc_calc_xmitsize(p->rate.rate, p->burst); fprintf(f, "burst %s ", sprint_size(buffer, b1)); fprintf(f, "mtu %s ", sprint_size(p->mtu, b1)); if (show_raw) fprintf(f, "[%08x] ", p->burst); if (p->peakrate.rate) fprintf(f, "peakrate %s ", sprint_rate(p->peakrate.rate, b1)); if (tb[TCA_POLICE_AVRATE]) fprintf(f, "avrate %s ", sprint_rate(rta_getattr_u32(tb[TCA_POLICE_AVRATE]), b1)); fprintf(f, "action %s", police_action_n2a(p->action, b1, sizeof(b1))); if (tb[TCA_POLICE_RESULT]) { fprintf(f, "/%s ", police_action_n2a(*(int*)RTA_DATA(tb[TCA_POLICE_RESULT]), b1, sizeof(b1))); } else fprintf(f, " "); fprintf(f, "overhead %ub ", p->rate.overhead); linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK); if (linklayer > TC_LINKLAYER_ETHERNET || show_details) fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2)); fprintf(f, "\nref %d bind %d\n",p->refcnt, p->bindcnt); return 0; }
int cthd_nl_wrapper::print_ctrl_cmds(FILE * fp, struct rtattr *arg, __u32 ctrl_ver) { struct rtattr *tb[CTRL_ATTR_OP_MAX + 1]; if (arg == NULL) return -1; parse_rtattr_nested(tb, CTRL_ATTR_OP_MAX, arg); if (tb[CTRL_ATTR_OP_ID]) { __u32 *id = (__u32*)RTA_DATA(tb[CTRL_ATTR_OP_ID]); fprintf(fp, " ID-0x%x ", *id); } return 0; }
static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) { struct rtattr *tb[TCA_DRR_MAX + 1]; SPRINT_BUF(b1); if (opt == NULL) return 0; parse_rtattr_nested(tb, TCA_DRR_MAX, opt); if (tb[TCA_DRR_QUANTUM]) fprintf(f, "quantum %s ", sprint_size(*(__u32 *)RTA_DATA(tb[TCA_DRR_QUANTUM]), b1)); return 0; }