| 52 | #include <netinet/ip_var.h> |
| 53 | |
| 54 | static int |
| 55 | rib4_preadd(u_int fibnum, const struct sockaddr *addr, const struct sockaddr *mask, |
| 56 | struct nhop_object *nh) |
| 57 | { |
| 58 | const struct sockaddr_in *addr4 = (const struct sockaddr_in *)addr; |
| 59 | uint16_t nh_type; |
| 60 | int rt_flags; |
| 61 | |
| 62 | /* XXX: RTF_LOCAL && RTF_MULTICAST */ |
| 63 | |
| 64 | rt_flags = nhop_get_rtflags(nh); |
| 65 | |
| 66 | if (rt_flags & RTF_HOST) { |
| 67 | /* |
| 68 | * Backward compatibility: |
| 69 | * if the destination is broadcast, |
| 70 | * mark route as broadcast. |
| 71 | * This behavior was useful when route cloning |
| 72 | * was in place, so there was an explicit cloned |
| 73 | * route for every broadcasted address. |
| 74 | * Currently (2020-04) there is no kernel machinery |
| 75 | * to do route cloning, though someone might explicitly |
| 76 | * add these routes to support some cases with active-active |
| 77 | * load balancing. Given that, retain this support. |
| 78 | */ |
| 79 | if (in_broadcast(addr4->sin_addr, nh->nh_ifp)) { |
| 80 | rt_flags |= RTF_BROADCAST; |
| 81 | nhop_set_rtflags(nh, rt_flags); |
| 82 | nh->nh_flags |= NHF_BROADCAST; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Check route MTU: |
| 88 | * inherit interface MTU if not set or |
| 89 | * check if MTU is too large. |
| 90 | */ |
| 91 | if (nh->nh_mtu == 0) { |
| 92 | nh->nh_mtu = nh->nh_ifp->if_mtu; |
| 93 | } else if (nh->nh_mtu > nh->nh_ifp->if_mtu) |
| 94 | nh->nh_mtu = nh->nh_ifp->if_mtu; |
| 95 | |
| 96 | /* Ensure that default route nhop has special flag */ |
| 97 | const struct sockaddr_in *mask4 = (const struct sockaddr_in *)mask; |
| 98 | if ((rt_flags & RTF_HOST) == 0 && mask4 != NULL && |
| 99 | mask4->sin_addr.s_addr == 0) |
| 100 | nh->nh_flags |= NHF_DEFAULT; |
| 101 | |
| 102 | /* Set nhop type to basic per-AF nhop */ |
| 103 | if (nhop_get_type(nh) == 0) { |
| 104 | if (nh->nh_flags & NHF_GATEWAY) |
| 105 | nh_type = NH_TYPE_IPV4_ETHER_NHOP; |
| 106 | else |
| 107 | nh_type = NH_TYPE_IPV4_ETHER_RSLV; |
| 108 | |
| 109 | nhop_set_type(nh, nh_type); |
| 110 | } |
| 111 |
nothing calls this directly
no test coverage detected