* Tries to add @rnd_add nhop to the existing set of nhops (@nh_orig) for the * prefix specified by @rt. * * Return 0 ans consumes rt / rnd_add nhop references. @rc gets populated * with the operation result. * Otherwise errno is returned. * * caller responsibility is to unlock/free rt and * rt->rt_nhop. */
| 91 | * rt->rt_nhop. |
| 92 | */ |
| 93 | int |
| 94 | add_route_mpath(struct rib_head *rnh, struct rt_addrinfo *info, |
| 95 | struct rtentry *rt, struct route_nhop_data *rnd_add, |
| 96 | struct route_nhop_data *rnd_orig, struct rib_cmd_info *rc) |
| 97 | { |
| 98 | RIB_RLOCK_TRACKER; |
| 99 | struct route_nhop_data rnd_new; |
| 100 | int error = 0; |
| 101 | |
| 102 | /* |
| 103 | * It is possible that multiple rtsock speakers will try to update |
| 104 | * the same route simultaneously. Reduce the chance of failing the |
| 105 | * request by retrying the cycle multiple times. |
| 106 | */ |
| 107 | for (int i = 0; i < RIB_MAX_RETRIES; i++) { |
| 108 | error = nhgrp_get_addition_group(rnh, rnd_orig, rnd_add, |
| 109 | &rnd_new); |
| 110 | if (error != 0) { |
| 111 | if (error != EAGAIN) |
| 112 | break; |
| 113 | |
| 114 | /* |
| 115 | * Group creation failed, most probably because |
| 116 | * @rnd_orig data got scheduled for deletion. |
| 117 | * Refresh @rnd_orig data and retry. |
| 118 | */ |
| 119 | RIB_RLOCK(rnh); |
| 120 | lookup_prefix(rnh, info, rnd_orig); |
| 121 | RIB_RUNLOCK(rnh); |
| 122 | continue; |
| 123 | } |
| 124 | |
| 125 | error = change_route_conditional(rnh, rt, info, rnd_orig, |
| 126 | &rnd_new, rc); |
| 127 | if (error != EAGAIN) |
| 128 | break; |
| 129 | RTSTAT_INC(rts_add_retry); |
| 130 | } |
| 131 | |
| 132 | if (V_fib_hash_outbound == 0 && error == 0 && |
| 133 | NH_IS_NHGRP(rc->rc_nh_new)) { |
| 134 | /* |
| 135 | * First multipath route got installed. Enable local |
| 136 | * outbound connections hashing. |
| 137 | */ |
| 138 | if (bootverbose) |
| 139 | printf("FIB: enabled flowid calculation for locally-originated packets\n"); |
| 140 | V_fib_hash_outbound = 1; |
| 141 | } |
| 142 | |
| 143 | return (error); |
| 144 | } |
| 145 | |
| 146 | struct rt_match_info { |
| 147 | struct rt_addrinfo *info; |
no test coverage detected