Lines Matching refs:nlm
156 struct nlmsghdr *nlm; in get_netlink() local
195 for (nlm = (struct nlmsghdr *)buf; in get_netlink()
196 NLMSG_OK(nlm, (size_t)bytes); in get_netlink()
197 nlm = NLMSG_NEXT(nlm, bytes)) in get_netlink()
199 r = callback(nlm); in get_netlink()
211 err_netlink(struct nlmsghdr *nlm) in err_netlink() argument
216 if (nlm->nlmsg_type != NLMSG_ERROR) in err_netlink()
218 l = nlm->nlmsg_len - sizeof(*nlm); in err_netlink()
223 err = (struct nlmsgerr *)NLMSG_DATA(nlm); in err_netlink()
231 link_route(struct nlmsghdr *nlm) in link_route() argument
239 if (nlm->nlmsg_type != RTM_DELROUTE) in link_route()
242 len = nlm->nlmsg_len - sizeof(*nlm); in link_route()
247 rtm = NLMSG_DATA(nlm); in link_route()
251 nlm->nlmsg_pid == (uint32_t)getpid()) in link_route()
254 len = NLMSG_PAYLOAD(nlm, sizeof(*rtm)); in link_route()
292 link_addr(struct nlmsghdr *nlm) in link_addr() argument
301 if (nlm->nlmsg_type != RTM_DELADDR && nlm->nlmsg_type != RTM_NEWADDR) in link_addr()
304 len = nlm->nlmsg_len - sizeof(*nlm); in link_addr()
309 if (nlm->nlmsg_pid == (uint32_t)getpid()) in link_addr()
311 ifa = NLMSG_DATA(nlm); in link_addr()
318 len = NLMSG_PAYLOAD(nlm, sizeof(*ifa)); in link_addr()
337 handle_ifa(nlm->nlmsg_type, ifn, &addr, &net, &dest); in link_addr()
342 link_netlink(struct nlmsghdr *nlm) in link_netlink() argument
349 len = link_route(nlm); in link_netlink()
352 len = link_addr(nlm); in link_netlink()
356 if (nlm->nlmsg_type != RTM_NEWLINK && nlm->nlmsg_type != RTM_DELLINK) in link_netlink()
358 len = nlm->nlmsg_len - sizeof(*nlm); in link_netlink()
363 ifi = NLMSG_DATA(nlm); in link_netlink()
367 len = NLMSG_PAYLOAD(nlm, sizeof(*ifi)); in link_netlink()
373 if (nlm->nlmsg_type == RTM_NEWLINK && in link_netlink()
384 if (nlm->nlmsg_type == RTM_DELLINK) { in link_netlink()
499 struct nlma *nlm; in if_address() local
502 nlm = xzalloc(sizeof(*nlm)); in if_address()
503 nlm->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); in if_address()
504 nlm->hdr.nlmsg_flags = NLM_F_REQUEST; in if_address()
506 nlm->hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; in if_address()
507 nlm->hdr.nlmsg_type = RTM_NEWADDR; in if_address()
509 nlm->hdr.nlmsg_type = RTM_DELADDR; in if_address()
510 if (!(nlm->ifa.ifa_index = if_nametoindex(iface->name))) { in if_address()
511 free(nlm); in if_address()
515 nlm->ifa.ifa_family = AF_INET; in if_address()
516 nlm->ifa.ifa_prefixlen = inet_ntocidr(*netmask); in if_address()
518 add_attr_l(&nlm->hdr, sizeof(*nlm), IFA_LABEL, in if_address()
520 add_attr_l(&nlm->hdr, sizeof(*nlm), IFA_LOCAL, in if_address()
523 add_attr_l(&nlm->hdr, sizeof(*nlm), IFA_BROADCAST, in if_address()
526 if (send_netlink(&nlm->hdr) == -1) in if_address()
528 free(nlm); in if_address()
535 struct nlmr *nlm; in if_route() local
544 nlm = xzalloc(sizeof(*nlm)); in if_route()
545 nlm->hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); in if_route()
546 nlm->hdr.nlmsg_type = RTM_NEWROUTE; in if_route()
548 nlm->hdr.nlmsg_flags = NLM_F_REPLACE; in if_route()
550 nlm->hdr.nlmsg_flags = NLM_F_CREATE /*| NLM_F_EXCL*/; in if_route()
552 nlm->hdr.nlmsg_type = RTM_DELROUTE; in if_route()
553 nlm->hdr.nlmsg_flags |= NLM_F_REQUEST; in if_route()
554 nlm->rt.rtm_family = AF_INET; in if_route()
555 nlm->rt.rtm_table = RT_TABLE_MAIN; in if_route()
558 nlm->rt.rtm_scope = RT_SCOPE_NOWHERE; in if_route()
560 nlm->hdr.nlmsg_flags |= NLM_F_CREATE /*| NLM_F_EXCL*/; in if_route()
565 nlm->rt.rtm_protocol = RTPROT_KERNEL; in if_route()
567 nlm->rt.rtm_protocol = RTPROT_BOOT; in if_route()
571 nlm->rt.rtm_scope = RT_SCOPE_LINK; in if_route()
573 nlm->rt.rtm_scope = RT_SCOPE_UNIVERSE; in if_route()
574 nlm->rt.rtm_type = RTN_UNICAST; in if_route()
577 nlm->rt.rtm_dst_len = inet_ntocidr(rt->net); in if_route()
578 add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_DST, in if_route()
580 if (nlm->rt.rtm_protocol == RTPROT_KERNEL) { in if_route()
581 add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_PREFSRC, in if_route()
587 add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_GATEWAY, in if_route()
590 add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_OIF, ifindex); in if_route()
591 add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_PRIORITY, rt->metric); in if_route()
593 if (send_netlink(&nlm->hdr) == -1) in if_route()
595 free(nlm); in if_route()