|
Lines 398-403
Link Here
|
| 398 |
struct sockaddr *dst, *gateway; |
398 |
struct sockaddr *dst, *gateway; |
| 399 |
{ |
399 |
{ |
| 400 |
register struct ifaddr *ifa; |
400 |
register struct ifaddr *ifa; |
|
|
401 |
struct rtentry *rt; |
| 402 |
|
| 403 |
ifa = 0; |
| 401 |
if ((flags & RTF_GATEWAY) == 0) { |
404 |
if ((flags & RTF_GATEWAY) == 0) { |
| 402 |
/* |
405 |
/* |
| 403 |
* If we are adding a route to an interface, |
406 |
* If we are adding a route to an interface, |
|
Lines 406-412
Link Here
|
| 406 |
* as our clue to the interface. Otherwise |
409 |
* as our clue to the interface. Otherwise |
| 407 |
* we can use the local address. |
410 |
* we can use the local address. |
| 408 |
*/ |
411 |
*/ |
| 409 |
ifa = 0; |
|
|
| 410 |
if (flags & RTF_HOST) { |
412 |
if (flags & RTF_HOST) { |
| 411 |
ifa = ifa_ifwithdstaddr(dst); |
413 |
ifa = ifa_ifwithdstaddr(dst); |
| 412 |
} |
414 |
} |
|
Lines 423-440
Link Here
|
| 423 |
if (ifa == 0) |
425 |
if (ifa == 0) |
| 424 |
ifa = ifa_ifwithnet(gateway); |
426 |
ifa = ifa_ifwithnet(gateway); |
| 425 |
if (ifa == 0) { |
427 |
if (ifa == 0) { |
| 426 |
struct rtentry *rt = rtalloc1(dst, 0, 0UL); |
428 |
rt = rtalloc1(dst, 0, 0UL); |
| 427 |
if (rt == 0) |
429 |
if (rt) { |
| 428 |
return (0); |
430 |
rt->rt_refcnt--; |
| 429 |
rt->rt_refcnt--; |
431 |
if (rt->rt_ifa) |
| 430 |
if ((ifa = rt->rt_ifa) == 0) |
432 |
ifa = rt->rt_ifa; |
| 431 |
return (0); |
433 |
} |
| 432 |
} |
434 |
} |
| 433 |
if (ifa->ifa_addr->sa_family != dst->sa_family) { |
435 |
if ((ifa) && (ifa->ifa_addr->sa_family != dst->sa_family)) { |
| 434 |
struct ifaddr *oifa = ifa; |
436 |
struct ifaddr *oifa = ifa; |
| 435 |
ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp); |
437 |
ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp); |
| 436 |
if (ifa == 0) |
438 |
if (ifa == 0) |
| 437 |
ifa = oifa; |
439 |
ifa = oifa; |
|
|
440 |
} |
| 441 |
/* |
| 442 |
* If we are adding a gateway, it is quite |
| 443 |
* possible that the routing table has a static |
| 444 |
* entry in place for the gateway, that may |
| 445 |
* not agree with info garnered from the interfaces. |
| 446 |
* The routing table should carry more precedence |
| 447 |
* than the interfaces in this matter. |
| 448 |
* Must be careful not to stomp on new entries from |
| 449 |
* rtinit, hence (ifa->ifa_addr != gateway). |
| 450 |
*/ |
| 451 |
if ((ifa == 0 || ifa->ifa_addr != gateway) && |
| 452 |
(rt = rtalloc1(gateway,0,0UL))) { |
| 453 |
rt->rt_refcnt--; |
| 454 |
ifa = rt->rt_ifa; |
| 438 |
} |
455 |
} |
| 439 |
return (ifa); |
456 |
return (ifa); |
| 440 |
} |
457 |
} |