本文整理汇总了C++中RTA_DATA函数的典型用法代码示例。如果您正苦于以下问题:C++ RTA_DATA函数的具体用法?C++ RTA_DATA怎么用?C++ RTA_DATA使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTA_DATA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: print_addrinfo
int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
void *arg)
{
FILE *fp = (FILE*)arg;
struct ifaddrmsg *ifa = NLMSG_DATA(n);
int len = n->nlmsg_len;
int deprecated = 0;
struct rtattr * rta_tb[IFA_MAX+1];
char abuf[256];
SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
return 0;
len -= NLMSG_LENGTH(sizeof(*ifa));
if (len < 0) {
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
return -1;
}
if (filter.flushb && n->nlmsg_type != RTM_NEWADDR)
return 0;
parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
if (!rta_tb[IFA_LOCAL])
rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
if (!rta_tb[IFA_ADDRESS])
rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL];
if (filter.ifindex && filter.ifindex != ifa->ifa_index)
return 0;
if ((filter.scope^ifa->ifa_scope)&filter.scopemask)
return 0;
if ((filter.flags^ifa->ifa_flags)&filter.flagmask)
return 0;
if (filter.label) {
SPRINT_BUF(b1);
const char *label;
if (rta_tb[IFA_LABEL])
label = RTA_DATA(rta_tb[IFA_LABEL]);
else
label = ll_idx_n2a(ifa->ifa_index, b1);
if (fnmatch(filter.label, label, 0) != 0)
return 0;
}
if (filter.pfx.family) {
if (rta_tb[IFA_LOCAL]) {
inet_prefix dst;
memset(&dst, 0, sizeof(dst));
dst.family = ifa->ifa_family;
memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen))
return 0;
}
}
if (filter.family && filter.family != ifa->ifa_family)
return 0;
if (filter.flushb) {
struct nlmsghdr *fn;
if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) {
if (flush_update())
return -1;
}
fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp));
memcpy(fn, n, n->nlmsg_len);
fn->nlmsg_type = RTM_DELADDR;
fn->nlmsg_flags = NLM_F_REQUEST;
fn->nlmsg_seq = ++rth.seq;
filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
filter.flushed++;
if (show_stats < 2)
return 0;
}
if (n->nlmsg_type == RTM_DELADDR)
fprintf(fp, "Deleted ");
if (filter.oneline || filter.flushb)
fprintf(fp, "%u: %s", ifa->ifa_index, ll_index_to_name(ifa->ifa_index));
if (ifa->ifa_family == AF_INET)
fprintf(fp, " inet ");
else if (ifa->ifa_family == AF_INET6)
fprintf(fp, " inet6 ");
else if (ifa->ifa_family == AF_DECnet)
fprintf(fp, " dnet ");
else if (ifa->ifa_family == AF_IPX)
fprintf(fp, " ipx ");
else
fprintf(fp, " family %d ", ifa->ifa_family);
if (rta_tb[IFA_LOCAL]) {
fprintf(fp, "%s", rt_addr_n2a(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
RTA_DATA(rta_tb[IFA_LOCAL]),
abuf, sizeof(abuf)));
if (rta_tb[IFA_ADDRESS] == NULL ||
memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]), 4) == 0) {
//.........这里部分代码省略.........
示例2: rtnl_print_ifinfo
static void rtnl_print_ifinfo(struct nlmsghdr *hdr)
{
struct ifinfomsg *ifi = NLMSG_DATA(hdr);
struct rtattr *attr = IFLA_RTA(ifi);
uint32_t attrs_len = IFLA_PAYLOAD(hdr);
char flags[256];
char if_addr[64] = {};
char *af_link = "unknown";
if (ifi->ifi_family == AF_UNSPEC)
af_link = "unspec";
else if (ifi->ifi_family == AF_BRIDGE)
af_link = "bridge";
tprintf(" [ Link Family %d (%s%s%s)", ifi->ifi_family,
colorize_start(bold), af_link, colorize_end());
tprintf(", Type %d (%s%s%s)", ifi->ifi_type,
colorize_start(bold),
device_type2str(ifi->ifi_type),
colorize_end());
tprintf(", Index %d", ifi->ifi_index);
tprintf(", Flags 0x%x (%s%s%s)", ifi->ifi_flags,
colorize_start(bold),
rtnl_link_flags2str(ifi->ifi_flags, flags,
sizeof(flags)),
colorize_end());
tprintf(", Change 0x%x (%s%s%s) ]\n", ifi->ifi_change,
colorize_start(bold),
rtnl_link_flags2str(ifi->ifi_change, flags,
sizeof(flags)),
colorize_end());
for (; RTA_OK(attr, attrs_len); attr = RTA_NEXT(attr, attrs_len)) {
switch (attr->rta_type) {
case IFLA_ADDRESS:
attr_fmt(attr, "Address %s",
device_addr2str(RTA_DATA(attr),
RTA_LEN(attr), ifi->ifi_type,
if_addr, sizeof(if_addr)));
break;
case IFLA_BROADCAST:
attr_fmt(attr, "Broadcast %s",
device_addr2str(RTA_DATA(attr),
RTA_LEN(attr), ifi->ifi_type,
if_addr, sizeof(if_addr)));
break;
case IFLA_IFNAME:
attr_fmt(attr, "Name %s%s%s",
colorize_start(bold), RTA_STR(attr),
colorize_end());
break;
case IFLA_MTU:
attr_fmt(attr, "MTU %d", RTA_INT(attr));
break;
case IFLA_LINK:
attr_fmt(attr, "Link %d", RTA_INT(attr));
break;
case IFLA_QDISC:
attr_fmt(attr, "QDisc %s", RTA_STR(attr));
break;
case IFLA_OPERSTATE:
{
uint8_t st = RTA_UINT8(attr);
char states[256];
attr_fmt(attr, "Operation state 0x%x (%s%s%s)",
st,
colorize_start(bold),
rtnl_link_operstate2str(st,
states, sizeof(states)),
colorize_end());
}
break;
case IFLA_LINKMODE:
{
uint8_t mode = RTA_UINT8(attr);
char str[32];
attr_fmt(attr, "Mode 0x%x (%s%s%s)", mode,
colorize_start(bold),
rtnl_link_mode2str(mode, str,
sizeof(str)),
colorize_end());
}
break;
case IFLA_GROUP:
attr_fmt(attr, "Group %d", RTA_INT(attr));
break;
case IFLA_TXQLEN:
attr_fmt(attr, "Tx queue len %d", RTA_INT(attr));
break;
case IFLA_NET_NS_PID:
attr_fmt(attr, "Network namespace pid %d",
RTA_INT(attr));
break;
case IFLA_NET_NS_FD:
attr_fmt(attr, "Network namespace fd %d",
RTA_INT(attr));
break;
}
//.........这里部分代码省略.........
示例3: rtnl_print_route
static void rtnl_print_route(struct nlmsghdr *hdr)
{
struct rtmsg *rtm = NLMSG_DATA(hdr);
uint32_t attrs_len = RTM_PAYLOAD(hdr);
struct rtattr *attr = RTM_RTA(rtm);
struct rta_cacheinfo *ci;
int hz = get_user_hz();
char addr_str[256];
char flags[256];
tprintf(" [ Route Family %d (%s%s%s)", rtm->rtm_family,
colorize_start(bold),
addr_family2str(rtm->rtm_family),
colorize_end());
tprintf(", Dst Len %d", rtm->rtm_dst_len);
tprintf(", Src Len %d", rtm->rtm_src_len);
tprintf(", ToS %d", rtm->rtm_tos);
tprintf(", Table %d (%s%s%s)", rtm->rtm_table,
colorize_start(bold),
route_table2str(rtm->rtm_table),
colorize_end());
tprintf(", Proto %d (%s%s%s)", rtm->rtm_protocol,
colorize_start(bold),
route_proto2str(rtm->rtm_protocol),
colorize_end());
tprintf(", Scope %d (%s%s%s)", rtm->rtm_scope,
colorize_start(bold),
scope2str(rtm->rtm_scope),
colorize_end());
tprintf(", Type %d (%s%s%s)", rtm->rtm_type,
colorize_start(bold),
route_type2str(rtm->rtm_type),
colorize_end());
tprintf(", Flags 0x%x (%s%s%s) ]\n", rtm->rtm_flags,
colorize_start(bold),
flags2str(route_flags, rtm->rtm_flags, flags,
sizeof(flags)),
colorize_end());
for (; RTA_OK(attr, attrs_len); attr = RTA_NEXT(attr, attrs_len)) {
switch (attr->rta_type) {
case RTA_DST:
attr_fmt(attr, "Dst %s", addr2str(rtm->rtm_family,
RTA_DATA(attr), addr_str, sizeof(addr_str)));
break;
case RTA_SRC:
attr_fmt(attr, "Src %s", addr2str(rtm->rtm_family,
RTA_DATA(attr), addr_str, sizeof(addr_str)));
break;
case RTA_IIF:
attr_fmt(attr, "Iif %d", RTA_INT(attr));
break;
case RTA_OIF:
attr_fmt(attr, "Oif %d", RTA_INT(attr));
break;
case RTA_GATEWAY:
attr_fmt(attr, "Gateway %s", addr2str(rtm->rtm_family,
RTA_DATA(attr), addr_str, sizeof(addr_str)));
break;
case RTA_PRIORITY:
attr_fmt(attr, "Priority %u", RTA_UINT32(attr));
break;
case RTA_PREFSRC:
attr_fmt(attr, "Pref Src %s", addr2str(rtm->rtm_family,
RTA_DATA(attr), addr_str, sizeof(addr_str)));
break;
case RTA_MARK:
attr_fmt(attr, "Mark 0x%x", RTA_UINT(attr));
break;
case RTA_FLOW:
attr_fmt(attr, "Flow 0x%x", RTA_UINT(attr));
break;
case RTA_TABLE:
attr_fmt(attr, "Table %d (%s%s%s)", RTA_UINT32(attr),
colorize_start(bold),
route_table2str(RTA_UINT32(attr)),
colorize_end());
break;
case RTA_CACHEINFO:
ci = RTA_DATA(attr);
tprintf("\tA: Cache (");
tprintf("expires(%ds)", ci->rta_expires / hz);
tprintf(", error(%d)", ci->rta_error);
tprintf(", users(%d)", ci->rta_clntref);
tprintf(", used(%d)", ci->rta_used);
tprintf(", last use(%ds)", ci->rta_lastuse / hz);
tprintf(", id(%d)", ci->rta_id);
tprintf(", ts(%d)", ci->rta_ts);
tprintf(", ts age(%ds))", ci->rta_tsage);
tprintf(", Len %lu\n", RTA_LEN(attr));
break;
}
}
}
示例4: xfrm_state_print
int xfrm_state_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
void *arg)
{
FILE *fp = (FILE*)arg;
struct rtattr * tb[XFRMA_MAX+1];
struct rtattr * rta;
struct xfrm_usersa_info *xsinfo = NULL;
struct xfrm_user_expire *xexp = NULL;
struct xfrm_usersa_id *xsid = NULL;
int len = n->nlmsg_len;
if (n->nlmsg_type != XFRM_MSG_NEWSA &&
n->nlmsg_type != XFRM_MSG_DELSA &&
n->nlmsg_type != XFRM_MSG_UPDSA &&
n->nlmsg_type != XFRM_MSG_EXPIRE) {
fprintf(stderr, "Not a state: %08x %08x %08x\n",
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
return 0;
}
if (n->nlmsg_type == XFRM_MSG_DELSA) {
/* Dont blame me for this .. Herbert made me do it */
xsid = NLMSG_DATA(n);
len -= NLMSG_SPACE(sizeof(*xsid));
} else if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
xexp = NLMSG_DATA(n);
xsinfo = &xexp->state;
len -= NLMSG_SPACE(sizeof(*xexp));
} else {
xexp = NULL;
xsinfo = NLMSG_DATA(n);
len -= NLMSG_SPACE(sizeof(*xsinfo));
}
if (len < 0) {
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
return -1;
}
if (xsinfo && !xfrm_state_filter_match(xsinfo))
return 0;
if (n->nlmsg_type == XFRM_MSG_DELSA)
fprintf(fp, "Deleted ");
else if (n->nlmsg_type == XFRM_MSG_UPDSA)
fprintf(fp, "Updated ");
else if (n->nlmsg_type == XFRM_MSG_EXPIRE)
fprintf(fp, "Expired ");
if (n->nlmsg_type == XFRM_MSG_DELSA)
rta = XFRMSID_RTA(xsid);
else if (n->nlmsg_type == XFRM_MSG_EXPIRE)
rta = XFRMEXP_RTA(xexp);
else
rta = XFRMS_RTA(xsinfo);
parse_rtattr(tb, XFRMA_MAX, rta, len);
if (n->nlmsg_type == XFRM_MSG_DELSA) {
//xfrm_policy_id_print();
if (!tb[XFRMA_SA]) {
fprintf(stderr, "Buggy XFRM_MSG_DELSA: no XFRMA_SA\n");
return -1;
}
if (RTA_PAYLOAD(tb[XFRMA_SA]) < sizeof(*xsinfo)) {
fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
return -1;
}
xsinfo = RTA_DATA(tb[XFRMA_SA]);
}
xfrm_state_info_print(xsinfo, tb, fp, NULL, NULL);
if (n->nlmsg_type == XFRM_MSG_EXPIRE) {
fprintf(fp, "\t");
fprintf(fp, "hard %u", xexp->hard);
fprintf(fp, "%s", _SL_);
}
if (oneline)
fprintf(fp, "\n");
fflush(fp);
return 0;
}
示例5: rtmon_check_defaults
/**
* Scan netlink message in the buffer for IPv6 default route changes.
*/
static int
rtmon_check_defaults(const void *buf, size_t len)
{
struct nlmsghdr *nh;
int dfltdiff = 0;
for (nh = (struct nlmsghdr *)buf;
NLMSG_OK(nh, len);
nh = NLMSG_NEXT(nh, len))
{
struct rtmsg *rtm;
struct rtattr *rta;
int attrlen;
int delta = 0;
const void *gwbuf;
size_t gwlen;
int oif;
DPRINTF2(("nlmsg type %d flags 0x%x\n",
nh->nlmsg_seq, nh->nlmsg_type, nh->nlmsg_flags));
if (nh->nlmsg_type == NLMSG_DONE) {
break;
}
if (nh->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *ne = (struct nlmsgerr *)NLMSG_DATA(nh);
DPRINTF2(("> error %d\n", ne->error));
LWIP_UNUSED_ARG(ne);
break;
}
if (nh->nlmsg_type < RTM_BASE || RTM_MAX <= nh->nlmsg_type) {
/* shouldn't happen */
DPRINTF2(("> not an RTM message!\n"));
continue;
}
rtm = (struct rtmsg *)NLMSG_DATA(nh);
attrlen = RTM_PAYLOAD(nh);
if (nh->nlmsg_type == RTM_NEWROUTE) {
delta = +1;
}
else if (nh->nlmsg_type == RTM_DELROUTE) {
delta = -1;
}
else {
/* shouldn't happen */
continue;
}
/*
* Is this an IPv6 default route in the main table? (Local
* table always has ::/0 reject route, hence the last check).
*/
if (rtm->rtm_family == AF_INET6 /* should always be true */
&& rtm->rtm_dst_len == 0
&& rtm->rtm_table == RT_TABLE_MAIN)
{
dfltdiff += delta;
}
else {
/* some other route change */
continue;
}
gwbuf = NULL;
gwlen = 0;
oif = -1;
for (rta = RTM_RTA(rtm);
RTA_OK(rta, attrlen);
rta = RTA_NEXT(rta, attrlen))
{
if (rta->rta_type == RTA_GATEWAY) {
gwbuf = RTA_DATA(rta);
gwlen = RTA_PAYLOAD(rta);
}
else if (rta->rta_type == RTA_OIF) {
/* assert RTA_PAYLOAD(rta) == 4 */
memcpy(&oif, RTA_DATA(rta), sizeof(oif));
}
}
/* XXX: TODO: note that { oif, gw } was added/removed */
LWIP_UNUSED_ARG(gwbuf);
LWIP_UNUSED_ARG(gwlen);
LWIP_UNUSED_ARG(oif);
}
return dfltdiff;
}
示例6: xfrm_policy_print
int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
void *arg)
{
struct rtattr * tb[XFRMA_MAX+1];
struct rtattr * rta;
struct xfrm_userpolicy_info *xpinfo = NULL;
struct xfrm_user_polexpire *xpexp = NULL;
struct xfrm_userpolicy_id *xpid = NULL;
__u8 ptype = XFRM_POLICY_TYPE_MAIN;
FILE *fp = (FILE*)arg;
int len = n->nlmsg_len;
if (n->nlmsg_type != XFRM_MSG_NEWPOLICY &&
n->nlmsg_type != XFRM_MSG_DELPOLICY &&
n->nlmsg_type != XFRM_MSG_UPDPOLICY &&
n->nlmsg_type != XFRM_MSG_POLEXPIRE) {
fprintf(stderr, "Not a policy: %08x %08x %08x\n",
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
return 0;
}
if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
xpid = NLMSG_DATA(n);
len -= NLMSG_SPACE(sizeof(*xpid));
} else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
xpexp = NLMSG_DATA(n);
xpinfo = &xpexp->pol;
len -= NLMSG_SPACE(sizeof(*xpexp));
} else {
xpexp = NULL;
xpinfo = NLMSG_DATA(n);
len -= NLMSG_SPACE(sizeof(*xpinfo));
}
if (len < 0) {
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
return -1;
}
if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
rta = XFRMPID_RTA(xpid);
else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
rta = XFRMPEXP_RTA(xpexp);
else
rta = XFRMP_RTA(xpinfo);
parse_rtattr(tb, XFRMA_MAX, rta, len);
if (tb[XFRMA_POLICY_TYPE]) {
struct xfrm_userpolicy_type *upt;
if (RTA_PAYLOAD(tb[XFRMA_POLICY_TYPE]) < sizeof(*upt)) {
fprintf(stderr, "too short XFRMA_POLICY_TYPE len\n");
return -1;
}
upt = (struct xfrm_userpolicy_type *)RTA_DATA(tb[XFRMA_POLICY_TYPE]);
ptype = upt->type;
}
if (xpinfo && !xfrm_policy_filter_match(xpinfo, ptype))
return 0;
if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
fprintf(fp, "Deleted ");
else if (n->nlmsg_type == XFRM_MSG_UPDPOLICY)
fprintf(fp, "Updated ");
else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
fprintf(fp, "Expired ");
if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
//xfrm_policy_id_print();
if (!tb[XFRMA_POLICY]) {
fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n");
return -1;
}
if (RTA_PAYLOAD(tb[XFRMA_POLICY]) < sizeof(*xpinfo)) {
fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
return -1;
}
xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]);
}
xfrm_policy_info_print(xpinfo, tb, fp, NULL, NULL);
if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
fprintf(fp, "\t");
fprintf(fp, "hard %u", xpexp->hard);
fprintf(fp, "%s", _SL_);
}
if (oneline)
fprintf(fp, "\n");
fflush(fp);
return 0;
}
示例7: print_spdinfo
static int print_spdinfo( struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE*)arg;
__u32 *f = NLMSG_DATA(n);
struct rtattr * tb[XFRMA_SPD_MAX+1];
struct rtattr * rta;
int len = n->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(__u32));
if (len < 0) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;
}
rta = XFRMSAPD_RTA(f);
parse_rtattr(tb, XFRMA_SPD_MAX, rta, len);
fprintf(fp,"\t SPD");
if (tb[XFRMA_SPD_INFO]) {
struct xfrmu_spdinfo *si;
if (RTA_PAYLOAD(tb[XFRMA_SPD_INFO]) < sizeof(*si)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;
}
si = RTA_DATA(tb[XFRMA_SPD_INFO]);
fprintf(fp," IN %d", si->incnt);
fprintf(fp," OUT %d", si->outcnt);
fprintf(fp," FWD %d", si->fwdcnt);
if (show_stats) {
fprintf(fp," (Sock:");
fprintf(fp," IN %d", si->inscnt);
fprintf(fp," OUT %d", si->outscnt);
fprintf(fp," FWD %d", si->fwdscnt);
fprintf(fp,")");
}
fprintf(fp, "%s", _SL_);
}
if (show_stats > 1) {
struct xfrmu_spdhinfo *sh;
if (tb[XFRMA_SPD_HINFO]) {
if (RTA_PAYLOAD(tb[XFRMA_SPD_HINFO]) < sizeof(*sh)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;
}
sh = RTA_DATA(tb[XFRMA_SPD_HINFO]);
fprintf(fp,"\t SPD buckets:");
fprintf(fp," count %d", sh->spdhcnt);
fprintf(fp," Max %d", sh->spdhmcnt);
fprintf(fp, "%s", _SL_);
}
if (tb[XFRMA_SPD_IPV4_HTHRESH]) {
struct xfrmu_spdhthresh *th;
if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV4_HTHRESH]) < sizeof(*th)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;
}
th = RTA_DATA(tb[XFRMA_SPD_IPV4_HTHRESH]);
fprintf(fp,"\t SPD IPv4 thresholds:");
fprintf(fp," local %d", th->lbits);
fprintf(fp," remote %d", th->rbits);
fprintf(fp, "%s", _SL_);
}
if (tb[XFRMA_SPD_IPV6_HTHRESH]) {
struct xfrmu_spdhthresh *th;
if (RTA_PAYLOAD(tb[XFRMA_SPD_IPV6_HTHRESH]) < sizeof(*th)) {
fprintf(stderr, "SPDinfo: Wrong len %d\n", len);
return -1;
}
th = RTA_DATA(tb[XFRMA_SPD_IPV6_HTHRESH]);
fprintf(fp,"\t SPD IPv6 thresholds:");
fprintf(fp," local %d", th->lbits);
fprintf(fp," remote %d", th->rbits);
fprintf(fp, "%s", _SL_);
}
}
if (oneline)
fprintf(fp, "\n");
return 0;
}
示例8: parse_nlmsg
struct ip4_routing_table * parse_nlmsg(struct nlmsghdr* msg)
{
char dst_temp[IP4_ALEN];
char gw_temp[IP4_ALEN];
unsigned int priority;
unsigned int interface;
struct ip4_routing_table *table_pointer = NULL;
switch (msg->nlmsg_type)
{
case NLMSG_ERROR:
{
struct nlmsgerr* errorMsg = (struct nlmsgerr*) NLMSG_DATA(msg);
PRINT_DEBUG("\nrecvd NLMSG_ERROR error seq:%d code:%d...", msg->nlmsg_seq, errorMsg->error);
break;
}
case RTM_NEWROUTE:
{
struct rtmsg* rtm = (struct rtmsg*) NLMSG_DATA(msg);
struct rtattr* rta = RTM_RTA(rtm);
int rtaLen = msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
if (rtm->rtm_type == RTN_UNICAST) // don't consider local, broadcast and unreachable routes
{
table_pointer = (struct ip4_routing_table*) malloc(
sizeof(struct ip4_routing_table));
memset(table_pointer, 0, sizeof(struct ip4_routing_table)); // zero the routing table entry data
for (; RTA_OK(rta, rtaLen); rta = RTA_NEXT(rta, rtaLen))
{
switch (rta->rta_type)
{
case RTA_DST: //destination
table_pointer->mask = rtm->rtm_dst_len;
memcpy(dst_temp, RTA_DATA(rta), IP4_ALEN);
PRINT_DEBUG("received RTA_DST");
PRINT_DEBUG("dst_str = %u.%u.%u.%u", dst_temp[0]&0xFF, dst_temp[1]&0xFF, dst_temp[2]&0xFF, dst_temp[3]&0xFF);
table_pointer->dst
= IP4_ADR_P2N(dst_temp[0]&0xFF, dst_temp[1]&0xFF, dst_temp[2]&0xFF, dst_temp[3]&0xFF);
break;
case RTA_GATEWAY: //next hop
table_pointer->mask = rtm->rtm_dst_len;
memcpy(gw_temp, RTA_DATA(rta), IP4_ALEN);
PRINT_DEBUG("received RTA_GATEWAY");
PRINT_DEBUG("gw_str = %u.%u.%u.%u",gw_temp[0]&0xFF, gw_temp[1]&0xFF, gw_temp[2]&0xFF, gw_temp[3]&0xFF);
table_pointer->gw
= IP4_ADR_P2N(gw_temp[0]&0xFF, gw_temp[1]&0xFF, gw_temp[2]&0xFF, gw_temp[3]&0xFF);
break;
case RTA_OIF: //interface
memcpy(&table_pointer->interface, RTA_DATA(rta),
sizeof(interface));
PRINT_DEBUG("interface:%u",table_pointer->interface);
break;
case RTA_PRIORITY: //metric
memcpy(&table_pointer->metric, RTA_DATA(rta),
sizeof(priority));
PRINT_DEBUG("metric:%u",table_pointer->metric);
break;
} //switch(rta->)
}// for()
} // if RTN_UNICAST
return (table_pointer);
}
} //switch (msg->nlmsg_type)
return (NULL);
}
示例9: bionic_ifaddrs_recvaddrs
static void bionic_ifaddrs_recvaddrs(int fd, struct ifaddrs **ifa, __u32 seq)
{
char buf[8192];
struct sockaddr_nl nladdr;
struct iovec iov = { buf, sizeof(buf) };
struct ifaddrmsg *m;
struct rtattr *rta_tb[IFA_MAX + 1];
struct ifaddrs *I;
while (1) {
int status;
struct nlmsghdr *h;
struct msghdr msg = {
(void*) &nladdr, sizeof(nladdr),
&iov, 1,
NULL, 0,
0
};
status = recvmsg(fd, &msg, 0);
if (status <= 0 || nladdr.nl_pid)
continue;
h = (struct nlmsghdr*) buf;
while (NLMSG_OK(h, status)) {
if (h->nlmsg_seq != seq)
goto skip_it;
switch (h->nlmsg_type) {
case NLMSG_DONE:
return;
case NLMSG_ERROR:
return;
case RTM_NEWADDR:
break;
default:
goto skip_it;
}
m = NLMSG_DATA(h);
#if HAVE_IPV6
if (m->ifa_family != AF_INET &&
m->ifa_family != AF_INET6)
#else /* HAVE_IPV6 */
if (m->ifa_family != AF_INET)
#endif /* !HAVE_IPV6 */
goto skip_it;
if (m->ifa_flags & IFA_F_TENTATIVE)
goto skip_it;
memset(rta_tb, 0, sizeof(rta_tb));
bionic_ifaddrs_parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(m), h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)));
if (rta_tb[IFA_LOCAL] == NULL)
rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
if (rta_tb[IFA_LOCAL] == NULL)
goto skip_it;
if (!(I = calloc(1, sizeof(struct ifaddrs))))
return;
I->ifa_name = calloc(IFNAMSIZ, sizeof(char));
I->ifa_flags = m->ifa_index;
I->ifa_addr = calloc(1, sizeof(struct sockaddr_storage));
I->ifa_addr->sa_family = m->ifa_family;
I->ifa_dstaddr = calloc(1, sizeof(struct sockaddr_storage));
I->ifa_netmask = calloc(1, sizeof(struct sockaddr_storage));
switch (m->ifa_family) {
case AF_INET: {
struct sockaddr_in *sin = (struct sockaddr_in*) I->ifa_addr;
memcpy(&sin->sin_addr, RTA_DATA(rta_tb[IFA_LOCAL]), sizeof(struct in_addr));
break;
}
case AF_INET6: {
struct sockaddr_in6 *sin = (struct sockaddr_in6*) I->ifa_addr;
memcpy(&sin->sin6_addr, RTA_DATA(rta_tb[IFA_LOCAL]), sizeof(struct in6_addr));
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr))
sin->sin6_scope_id = I->ifa_flags;
break;
}
default:
break;
}
I->ifa_next = *ifa;
*ifa = I;
skip_it:
h = NLMSG_NEXT(h, status);
}
if (msg.msg_flags & MSG_TRUNC)
continue;
}
//.........这里部分代码省略.........
示例10: netlink_if_link_filter
/* Netlink interface link lookup filter */
static int
netlink_if_link_filter(struct sockaddr_nl *snl, struct nlmsghdr *h)
{
struct ifinfomsg *ifi;
struct rtattr *tb[IFLA_MAX + 1];
interface_t *ifp;
int i, len;
char *name;
ifi = NLMSG_DATA(h);
if (h->nlmsg_type != RTM_NEWLINK)
return 0;
len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifinfomsg));
if (len < 0)
return -1;
/* Interface name lookup */
memset(tb, 0, sizeof (tb));
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == NULL)
return -1;
name = (char *) RTA_DATA(tb[IFLA_IFNAME]);
/* Return if loopback */
if (ifi->ifi_type == ARPHRD_LOOPBACK)
return 0;
/* Skip it if already exist */
ifp = if_get_by_ifname(name);
if (ifp) {
if (!ifp->vmac) {
vmac_reflect_flags(ifi);
ifp->flags = ifi->ifi_flags;
}
return 0;
}
/* Fill the interface structure */
ifp = (interface_t *) MALLOC(sizeof(interface_t));
memcpy(ifp->ifname, name, strlen(name));
ifp->ifindex = ifi->ifi_index;
ifp->mtu = *(int *) RTA_DATA(tb[IFLA_MTU]);
ifp->hw_type = ifi->ifi_type;
if (!ifp->vmac) {
vmac_reflect_flags(ifi);
ifp->flags = ifi->ifi_flags;
ifp->base_ifindex = ifi->ifi_index;
}
if (tb[IFLA_ADDRESS]) {
int hw_addr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
if (hw_addr_len > IF_HWADDR_MAX)
log_message(LOG_ERR, "MAC address for %s is too large: %d",
name, hw_addr_len);
else {
ifp->hw_addr_len = hw_addr_len;
memcpy(ifp->hw_addr, RTA_DATA(tb[IFLA_ADDRESS]),
hw_addr_len);
for (i = 0; i < hw_addr_len; i++)
if (ifp->hw_addr[i] != 0)
break;
if (i == hw_addr_len)
ifp->hw_addr_len = 0;
else
ifp->hw_addr_len = hw_addr_len;
}
}
/* Queue this new interface_t */
if_add_queue(ifp);
return 0;
}
示例11: virNetDevVPortProfileGetStatus
/**
* virNetDevVPortProfileGetStatus:
*
* tb: top level netlink response attributes + values
* vf: The virtual function used in the request
* instanceId: instanceId of the interface (vm uuid in case of 802.1Qbh)
* is8021Qbg: whether this function is call for 8021Qbg
* status: pointer to a uint16 where the status will be written into
*
* Get the status from the IFLA_PORT_RESPONSE field; Returns 0 in
* case of success, < 0 otherwise with error having been reported
*/
static int
virNetDevVPortProfileGetStatus(struct nlattr **tb, int32_t vf,
const unsigned char *instanceId,
bool nltarget_kernel,
bool is8021Qbg,
uint16_t *status)
{
int rc = -1;
struct nlattr *tb_port[IFLA_PORT_MAX + 1] = { NULL, };
if (vf == PORT_SELF_VF && nltarget_kernel) {
if (tb[IFLA_PORT_SELF]) {
if (nla_parse_nested(tb_port, IFLA_PORT_MAX, tb[IFLA_PORT_SELF],
ifla_port_policy)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("error parsing IFLA_PORT_SELF part"));
goto cleanup;
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("IFLA_PORT_SELF is missing"));
goto cleanup;
}
} else {
if (tb[IFLA_VF_PORTS]) {
int rem;
bool found = false;
struct nlattr *tb_vf_ports = { NULL, };
nla_for_each_nested(tb_vf_ports, tb[IFLA_VF_PORTS], rem) {
if (nla_type(tb_vf_ports) != IFLA_VF_PORT) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("error while iterating over "
"IFLA_VF_PORTS part"));
goto cleanup;
}
if (nla_parse_nested(tb_port, IFLA_PORT_MAX, tb_vf_ports,
ifla_port_policy)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("error parsing IFLA_VF_PORT part"));
goto cleanup;
}
if (instanceId &&
tb_port[IFLA_PORT_INSTANCE_UUID] &&
!memcmp(instanceId,
(unsigned char *)
RTA_DATA(tb_port[IFLA_PORT_INSTANCE_UUID]),
VIR_UUID_BUFLEN) &&
tb_port[IFLA_PORT_VF] &&
vf == *(uint32_t *)RTA_DATA(tb_port[IFLA_PORT_VF])) {
found = true;
break;
}
}
if (!found) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not find netlink response with "
"expected parameters"));
goto cleanup;
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("IFLA_VF_PORTS is missing"));
goto cleanup;
}
}
示例12: recvaddrs
static void recvaddrs(int fd, struct ifaddrs **ifa, __u32 seq)
{
char buf[8192];
struct sockaddr_nl nladdr;
struct iovec iov = { buf, sizeof(buf) };
struct ifaddrmsg *m;
struct rtattr * rta_tb[IFA_MAX+1];
struct ifaddrs *I;
while (1) {
int status;
struct nlmsghdr *h;
struct msghdr msg = {
(void*)&nladdr, sizeof(nladdr),
&iov, 1,
NULL, 0,
0
};
status = recvmsg(fd, &msg, 0);
if (status < 0)
continue;
if (status == 0)
return;
if (nladdr.nl_pid) /* Message not from kernel */
continue;
h = (struct nlmsghdr*)buf;
while (NLMSG_OK(h, status)) {
if (h->nlmsg_seq != seq)
goto skip_it;
if (h->nlmsg_type == NLMSG_DONE)
return;
if (h->nlmsg_type == NLMSG_ERROR)
return;
if (h->nlmsg_type != RTM_NEWADDR)
goto skip_it;
m = NLMSG_DATA(h);
if (m->ifa_family != AF_INET &&
m->ifa_family != AF_INET6)
goto skip_it;
if (m->ifa_flags&IFA_F_TENTATIVE)
goto skip_it;
memset(rta_tb, 0, sizeof(rta_tb));
parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(m), h->nlmsg_len - NLMSG_LENGTH(sizeof(*m)));
if (rta_tb[IFA_LOCAL] == NULL)
rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
if (rta_tb[IFA_LOCAL] == NULL)
goto skip_it;
I = malloc(sizeof(struct ifaddrs));
if (!I)
return;
memset(I, 0, sizeof(*I));
I->ifa_ifindex = m->ifa_index;
I->ifa_addr = (struct sockaddr*)&I->ifa_addrbuf;
I->ifa_addr->sa_family = m->ifa_family;
if (m->ifa_family == AF_INET) {
struct sockaddr_in *sin = (void*)I->ifa_addr;
memcpy(&sin->sin_addr, RTA_DATA(rta_tb[IFA_LOCAL]), 4);
} else {
struct sockaddr_in6 *sin = (void*)I->ifa_addr;
memcpy(&sin->sin6_addr, RTA_DATA(rta_tb[IFA_LOCAL]), 16);
if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr))
sin->sin6_scope_id = I->ifa_ifindex;
}
I->ifa_next = *ifa;
*ifa = I;
skip_it:
h = NLMSG_NEXT(h, status);
}
if (msg.msg_flags & MSG_TRUNC)
continue;
}
return;
}
示例13: if_nameindex_netlink
static struct if_nameindex *
if_nameindex_netlink (void)
{
struct netlink_handle nh = { 0, 0, 0, NULL, NULL };
struct if_nameindex *idx = NULL;
if (__netlink_open (&nh) < 0)
return NULL;
/* Tell the kernel that we wish to get a list of all
active interfaces. Collect all data for every interface. */
if (__netlink_request (&nh, RTM_GETLINK) < 0)
goto exit_free;
/* Count the interfaces. */
unsigned int nifs = 0;
for (struct netlink_res *nlp = nh.nlm_list; nlp; nlp = nlp->next)
{
struct nlmsghdr *nlh;
size_t size = nlp->size;
if (nlp->nlh == NULL)
continue;
/* Walk through all entries we got from the kernel and look, which
message type they contain. */
for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size))
{
/* Check if the message is what we want. */
if ((pid_t) nlh->nlmsg_pid != nh.pid || nlh->nlmsg_seq != nlp->seq)
continue;
if (nlh->nlmsg_type == NLMSG_DONE)
break; /* ok */
if (nlh->nlmsg_type == RTM_NEWLINK)
++nifs;
}
}
idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
if (idx == NULL)
{
nomem:
__set_errno (ENOBUFS);
goto exit_free;
}
/* Add the interfaces. */
nifs = 0;
for (struct netlink_res *nlp = nh.nlm_list; nlp; nlp = nlp->next)
{
struct nlmsghdr *nlh;
size_t size = nlp->size;
if (nlp->nlh == NULL)
continue;
/* Walk through all entries we got from the kernel and look, which
message type they contain. */
for (nlh = nlp->nlh; NLMSG_OK (nlh, size); nlh = NLMSG_NEXT (nlh, size))
{
/* Check if the message is what we want. */
if ((pid_t) nlh->nlmsg_pid != nh.pid || nlh->nlmsg_seq != nlp->seq)
continue;
if (nlh->nlmsg_type == NLMSG_DONE)
break; /* ok */
if (nlh->nlmsg_type == RTM_NEWLINK)
{
struct ifinfomsg *ifim = (struct ifinfomsg *) NLMSG_DATA (nlh);
struct rtattr *rta = IFLA_RTA (ifim);
size_t rtasize = IFLA_PAYLOAD (nlh);
idx[nifs].if_index = ifim->ifi_index;
while (RTA_OK (rta, rtasize))
{
char *rta_data = RTA_DATA (rta);
size_t rta_payload = RTA_PAYLOAD (rta);
if (rta->rta_type == IFLA_IFNAME)
{
idx[nifs].if_name = __strndup (rta_data, rta_payload);
if (idx[nifs].if_name == NULL)
{
idx[nifs].if_index = 0;
__if_freenameindex (idx);
idx = NULL;
goto nomem;
}
break;
}
rta = RTA_NEXT (rta, rtasize);
}
++nifs;
//.........这里部分代码省略.........
示例14: fillup_entry_info
int
fillup_entry_info(netsnmp_arp_entry *entry, struct nlmsghdr *nlmp)
{
struct ndmsg *rtmp;
struct in6_addr *in6p;
struct rtattr *tb[NDA_MAX + 1], *rta;
size_t in_len, out_len;
unsigned int i;
int length;
char addr[40];
u_char *buf;
u_char *hwaddr;
rtmp = (struct ndmsg *) NLMSG_DATA(nlmp);
if (nlmp->nlmsg_type != RTM_NEWNEIGH) {
snmp_log(LOG_ERR, "Wrong netlink message type %d\n", nlmp->nlmsg_type);
return -1;
}
if (rtmp->ndm_state != NUD_NOARP) {
memset(tb, 0, sizeof(struct rtattr *) * (NDA_MAX + 1));
length = nlmp->nlmsg_len - NLMSG_LENGTH(sizeof(*rtmp));
if (length < 0) {
snmp_log(LOG_ERR, "netlink message length %d < %d is invalid\n",
nlmp->nlmsg_len, NLMSG_LENGTH(sizeof(*rtmp)));
return -1;
}
/*
* this is what the kernel-removed NDA_RTA define did
*/
rta = ((struct rtattr *) (((char *) (rtmp)) +
NLMSG_ALIGN(sizeof(struct ndmsg))));
while (RTA_OK(rta, length)) {
if (rta->rta_type <= NDA_MAX)
tb[rta->rta_type] = rta;
rta = RTA_NEXT(rta, length);
}
if (length) {
snmp_log(LOG_ERR, "Received uneven number of netlink"
" messages - %d bytes remaining\n", length);
return -1;
}
/*
* Fill up the index
*/
entry->if_index = rtmp->ndm_ifindex;
/*
* Fill up ip address
*/
if (tb[NDA_DST]) {
memset(&addr, '\0', sizeof(addr));
in6p = (struct in6_addr *) RTA_DATA(tb[NDA_DST]);
sprintf(addr, NIP6_FMT, NIP6(*in6p));
in_len = entry->arp_ipaddress_len =
sizeof(entry->arp_ipaddress);
netsnmp_assert(16 == in_len);
out_len = 0;
buf = entry->arp_ipaddress;
if (1 != netsnmp_hex_to_binary(&buf, &in_len,
&out_len, 0, addr, ":")) {
snmp_log(LOG_ERR, "error parsing '%s', skipping\n",
entry->arp_ipaddress);
return -1;
}
netsnmp_assert(16 == out_len);
entry->arp_ipaddress_len = out_len;
}
if (tb[NDA_LLADDR]) {
memset(&addr, '\0', sizeof(addr));
hwaddr = RTA_DATA(tb[NDA_LLADDR]);
entry->arp_physaddress_len = RTA_PAYLOAD(tb[NDA_LLADDR]);
buf = entry->arp_physaddress;
for (i = 0; i < entry->arp_physaddress_len; i++)
entry->arp_physaddress[i] = hwaddr[i];
}
switch (rtmp->ndm_state) {
case NUD_INCOMPLETE:
entry->arp_state = INETNETTOMEDIASTATE_INCOMPLETE;
break;
case NUD_REACHABLE:
case NUD_PERMANENT:
entry->arp_state = INETNETTOMEDIASTATE_REACHABLE;
break;
case NUD_STALE:
entry->arp_state = INETNETTOMEDIASTATE_STALE;
break;
case NUD_DELAY:
entry->arp_state = INETNETTOMEDIASTATE_DELAY;
break;
case NUD_PROBE:
entry->arp_state = INETNETTOMEDIASTATE_PROBE;
break;
case NUD_FAILED:
entry->arp_state = INETNETTOMEDIASTATE_INVALID;
break;
case NUD_NONE:
entry->arp_state = INETNETTOMEDIASTATE_UNKNOWN;
break;
default:
//.........这里部分代码省略.........
示例15: filter_nlmsg
static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
{
struct rtmsg *r = NLMSG_DATA(n);
inet_prefix dst;
inet_prefix src;
inet_prefix via;
inet_prefix prefsrc;
__u32 table;
static int ip6_multiple_tables;
table = rtm_get_table(r, tb);
if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN)
ip6_multiple_tables = 1;
if (filter.cloned == !(r->rtm_flags&RTM_F_CLONED))
return 0;
if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) {
if (filter.tb) {
if (filter.tb == RT_TABLE_LOCAL) {
if (r->rtm_type != RTN_LOCAL)
return 0;
} else if (filter.tb == RT_TABLE_MAIN) {
if (r->rtm_type == RTN_LOCAL)
return 0;
} else {
return 0;
}
}
} else {
if (filter.tb > 0 && filter.tb != table)
return 0;
}
if ((filter.protocol^r->rtm_protocol)&filter.protocolmask)
return 0;
if ((filter.scope^r->rtm_scope)&filter.scopemask)
return 0;
if ((filter.type^r->rtm_type)&filter.typemask)
return 0;
if ((filter.tos^r->rtm_tos)&filter.tosmask)
return 0;
if (filter.rdst.family &&
(r->rtm_family != filter.rdst.family || filter.rdst.bitlen > r->rtm_dst_len))
return 0;
if (filter.mdst.family &&
(r->rtm_family != filter.mdst.family ||
(filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len)))
return 0;
if (filter.rsrc.family &&
(r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > r->rtm_src_len))
return 0;
if (filter.msrc.family &&
(r->rtm_family != filter.msrc.family ||
(filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len)))
return 0;
if (filter.rvia.family && r->rtm_family != filter.rvia.family)
return 0;
if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family)
return 0;
memset(&dst, 0, sizeof(dst));
dst.family = r->rtm_family;
if (tb[RTA_DST])
memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8);
if (filter.rsrc.family || filter.msrc.family) {
memset(&src, 0, sizeof(src));
src.family = r->rtm_family;
if (tb[RTA_SRC])
memcpy(&src.data, RTA_DATA(tb[RTA_SRC]), (r->rtm_src_len+7)/8);
}
if (filter.rvia.bitlen>0) {
memset(&via, 0, sizeof(via));
via.family = r->rtm_family;
if (tb[RTA_GATEWAY])
memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
}
if (filter.rprefsrc.bitlen>0) {
memset(&prefsrc, 0, sizeof(prefsrc));
prefsrc.family = r->rtm_family;
if (tb[RTA_PREFSRC])
memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8);
}
if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen))
return 0;
if (filter.mdst.family && filter.mdst.bitlen >= 0 &&
inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len))
return 0;
if (filter.rsrc.family && inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen))
return 0;
if (filter.msrc.family && filter.msrc.bitlen >= 0 &&
inet_addr_match(&src, &filter.msrc, r->rtm_src_len))
return 0;
if (filter.rvia.family && inet_addr_match(&via, &filter.rvia, filter.rvia.bitlen))
return 0;
if (filter.rprefsrc.family && inet_addr_match(&prefsrc, &filter.rprefsrc, filter.rprefsrc.bitlen))
return 0;
//.........这里部分代码省略.........