Changeset View
Changeset View
Standalone View
Standalone View
sys/netlink/route/nexthop.c
Show First 20 Lines • Show All 449 Lines • ▼ Show 20 Lines | dump_nhop(const struct nhop_object *nh, uint32_t uidx, struct nlmsghdr *hdr, | ||||
nhm->nh_flags = 0; | nhm->nh_flags = 0; | ||||
if (uidx != 0) | if (uidx != 0) | ||||
nlattr_add_u32(nw, NHA_ID, uidx); | nlattr_add_u32(nw, NHA_ID, uidx); | ||||
if (nh->nh_flags & NHF_BLACKHOLE) { | if (nh->nh_flags & NHF_BLACKHOLE) { | ||||
nlattr_add_flag(nw, NHA_BLACKHOLE); | nlattr_add_flag(nw, NHA_BLACKHOLE); | ||||
goto done; | goto done; | ||||
} | } | ||||
nlattr_add_u32(nw, NHA_OIF, nh->nh_ifp->if_index); | nlattr_add_u32(nw, NHA_OIF, if_getindex(nh->nh_ifp)); | ||||
switch (nh->gw_sa.sa_family) { | switch (nh->gw_sa.sa_family) { | ||||
#ifdef INET | #ifdef INET | ||||
case AF_INET: | case AF_INET: | ||||
nlattr_add(nw, NHA_GATEWAY, 4, &nh->gw4_sa.sin_addr); | nlattr_add(nw, NHA_GATEWAY, 4, &nh->gw4_sa.sin_addr); | ||||
break; | break; | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
case AF_INET6: | case AF_INET6: | ||||
{ | { | ||||
struct in6_addr addr = nh->gw6_sa.sin6_addr; | struct in6_addr addr = nh->gw6_sa.sin6_addr; | ||||
in6_clearscope(&addr); | in6_clearscope(&addr); | ||||
nlattr_add(nw, NHA_GATEWAY, 16, &addr); | nlattr_add(nw, NHA_GATEWAY, 16, &addr); | ||||
break; | break; | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
int off = nlattr_add_nested(nw, NHA_FREEBSD); | int off = nlattr_add_nested(nw, NHA_FREEBSD); | ||||
if (off != 0) { | if (off != 0) { | ||||
nlattr_add_u32(nw, NHAF_AIF, nh->nh_aifp->if_index); | nlattr_add_u32(nw, NHAF_AIF, if_getindex(nh->nh_aifp)); | ||||
if (uidx == 0) { | if (uidx == 0) { | ||||
nlattr_add_u32(nw, NHAF_KID, nhop_get_idx(nh)); | nlattr_add_u32(nw, NHAF_KID, nhop_get_idx(nh)); | ||||
nlattr_add_u32(nw, NHAF_FAMILY, nhop_get_upper_family(nh)); | nlattr_add_u32(nw, NHAF_FAMILY, nhop_get_upper_family(nh)); | ||||
nlattr_add_u32(nw, NHAF_TABLE, nhop_get_fibnum(nh)); | nlattr_add_u32(nw, NHAF_TABLE, nhop_get_fibnum(nh)); | ||||
} | } | ||||
nlattr_set_len(nw, off); | nlattr_set_len(nw, off); | ||||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | if (count == 0 || (count * sizeof(*grp) != data_len)) { | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
*((struct nlattr **)target) = nla; | *((struct nlattr **)target) = nla; | ||||
return (error); | return (error); | ||||
} | } | ||||
static void | static void | ||||
set_scope6(struct sockaddr *sa, struct ifnet *ifp) | set_scope6(struct sockaddr *sa, if_t ifp) | ||||
{ | { | ||||
#ifdef INET6 | #ifdef INET6 | ||||
if (sa != NULL && sa->sa_family == AF_INET6 && ifp != NULL) { | if (sa != NULL && sa->sa_family == AF_INET6 && ifp != NULL) { | ||||
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; | struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa; | ||||
if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr)) | if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr)) | ||||
in6_set_unicast_scopeid(&sa6->sin6_addr, if_getindex(ifp)); | in6_set_unicast_scopeid(&sa6->sin6_addr, if_getindex(ifp)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Sets nexthop @nh gateway specified by @gw. | * Sets nexthop @nh gateway specified by @gw. | ||||
* If gateway is IPv6 link-local, alters @gw to include scopeid equal to | * If gateway is IPv6 link-local, alters @gw to include scopeid equal to | ||||
* @ifp ifindex. | * @ifp ifindex. | ||||
* Returns 0 on success or errno. | * Returns 0 on success or errno. | ||||
*/ | */ | ||||
int | int | ||||
nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw, struct ifnet *ifp, | nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw, if_t ifp, | ||||
struct nl_pstate *npt) | struct nl_pstate *npt) | ||||
{ | { | ||||
#ifdef INET6 | #ifdef INET6 | ||||
if (gw->sa_family == AF_INET6) { | if (gw->sa_family == AF_INET6) { | ||||
struct sockaddr_in6 *gw6 = (struct sockaddr_in6 *)gw; | struct sockaddr_in6 *gw6 = (struct sockaddr_in6 *)gw; | ||||
if (IN6_IS_ADDR_LINKLOCAL(&gw6->sin6_addr)) { | if (IN6_IS_ADDR_LINKLOCAL(&gw6->sin6_addr)) { | ||||
if (ifp == NULL) { | if (ifp == NULL) { | ||||
NLMSG_REPORT_ERR_MSG(npt, "interface not set"); | NLMSG_REPORT_ERR_MSG(npt, "interface not set"); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
in6_set_unicast_scopeid(&gw6->sin6_addr, ifp->if_index); | in6_set_unicast_scopeid(&gw6->sin6_addr, if_getindex(ifp)); | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
nhop_set_gw(nh, gw, true); | nhop_set_gw(nh, gw, true); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | rtnl_handle_newnhop(struct nlmsghdr *hdr, struct nlpcb *nlp, | ||||
if (attrs.nha_id == 0) { | if (attrs.nha_id == 0) { | ||||
attrs.nha_id = find_spare_uidx(ctl); | attrs.nha_id = find_spare_uidx(ctl); | ||||
if (attrs.nha_id == 0) { | if (attrs.nha_id == 0) { | ||||
NL_LOG(LOG_DEBUG, "Unable to get spare uidx"); | NL_LOG(LOG_DEBUG, "Unable to get spare uidx"); | ||||
return (ENOSPC); | return (ENOSPC); | ||||
} | } | ||||
} | } | ||||
NL_LOG(LOG_DEBUG, "IFINDEX %d", attrs.nha_oif ? attrs.nha_oif->if_index : 0); | NL_LOG(LOG_DEBUG, "IFINDEX %d", attrs.nha_oif ? if_getindex(attrs.nha_oif) : 0); | ||||
unhop = malloc(sizeof(struct user_nhop), M_NETLINK, M_NOWAIT | M_ZERO); | unhop = malloc(sizeof(struct user_nhop), M_NETLINK, M_NOWAIT | M_ZERO); | ||||
if (unhop == NULL) { | if (unhop == NULL) { | ||||
NL_LOG(LOG_DEBUG, "Unable to allocate user_nhop"); | NL_LOG(LOG_DEBUG, "Unable to allocate user_nhop"); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
unhop->un_idx = attrs.nha_id; | unhop->un_idx = attrs.nha_id; | ||||
unhop->un_protocol = attrs.nh_protocol; | unhop->un_protocol = attrs.nh_protocol; | ||||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |