route.c (40561) | route.c (43313) |
---|---|
1/* 2 * PPP Routing related Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * PPP Routing related Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: route.c,v 1.53 1998/08/17 06:42:40 brian Exp $ | 20 * $Id: route.c,v 1.54 1998/10/22 02:32:50 brian Exp $ |
21 * 22 */ 23 | 21 * 22 */ 23 |
24#include <sys/types.h> | 24#include <sys/param.h> |
25#include <sys/socket.h> 26#include <net/if_types.h> 27#include <net/route.h> 28#include <net/if.h> 29#include <netinet/in.h> 30#include <arpa/inet.h> 31#include <net/if_dl.h> 32#include <netinet/in_systm.h> --- 20 unchanged lines hidden (view full) --- 53#include "lcp.h" 54#include "ccp.h" 55#include "link.h" 56#include "slcompress.h" 57#include "ipcp.h" 58#include "filter.h" 59#include "descriptor.h" 60#include "mp.h" | 25#include <sys/socket.h> 26#include <net/if_types.h> 27#include <net/route.h> 28#include <net/if.h> 29#include <netinet/in.h> 30#include <arpa/inet.h> 31#include <net/if_dl.h> 32#include <netinet/in_systm.h> --- 20 unchanged lines hidden (view full) --- 53#include "lcp.h" 54#include "ccp.h" 55#include "link.h" 56#include "slcompress.h" 57#include "ipcp.h" 58#include "filter.h" 59#include "descriptor.h" 60#include "mp.h" |
61#ifndef NORADIUS 62#include "radius.h" 63#endif |
|
61#include "bundle.h" 62#include "route.h" 63#include "prompt.h" 64#include "iface.h" 65 66static void 67p_sockaddr(struct prompt *prompt, struct sockaddr *phost, 68 struct sockaddr *pmask, int width) --- 412 unchanged lines hidden (view full) --- 481 bundle_SetRoute(bundle, RTM_DELETE, del, none, none, 1, 0); 482 } 483} 484 485void 486route_Add(struct sticky_route **rp, int type, struct in_addr dst, 487 struct in_addr mask, struct in_addr gw) 488{ | 64#include "bundle.h" 65#include "route.h" 66#include "prompt.h" 67#include "iface.h" 68 69static void 70p_sockaddr(struct prompt *prompt, struct sockaddr *phost, 71 struct sockaddr *pmask, int width) --- 412 unchanged lines hidden (view full) --- 484 bundle_SetRoute(bundle, RTM_DELETE, del, none, none, 1, 0); 485 } 486} 487 488void 489route_Add(struct sticky_route **rp, int type, struct in_addr dst, 490 struct in_addr mask, struct in_addr gw) 491{ |
489 if (type != ROUTE_STATIC) { 490 struct sticky_route *r; 491 int dsttype = type & ROUTE_DSTANY; | 492 struct sticky_route *r; 493 int dsttype = type & ROUTE_DSTANY; |
492 | 494 |
493 r = NULL; 494 while (*rp) { 495 if ((dsttype && dsttype == ((*rp)->type & ROUTE_DSTANY)) || 496 (!dsttype && (*rp)->dst.s_addr == dst.s_addr)) { 497 r = *rp; 498 *rp = r->next; 499 } else 500 rp = &(*rp)->next; 501 } 502 503 if (!r) 504 r = (struct sticky_route *)malloc(sizeof(struct sticky_route)); 505 r->type = type; 506 r->next = NULL; 507 r->dst = dst; 508 r->mask = mask; 509 r->gw = gw; 510 *rp = r; | 495 r = NULL; 496 while (*rp) { 497 if ((dsttype && dsttype == ((*rp)->type & ROUTE_DSTANY)) || 498 (!dsttype && (*rp)->dst.s_addr == dst.s_addr)) { 499 /* Oops, we already have this route - unlink it */ 500 free(r); /* impossible really */ 501 r = *rp; 502 *rp = r->next; 503 } else 504 rp = &(*rp)->next; |
511 } | 505 } |
506 507 if (!r) 508 r = (struct sticky_route *)malloc(sizeof(struct sticky_route)); 509 r->type = type; 510 r->next = NULL; 511 r->dst = dst; 512 r->mask = mask; 513 r->gw = gw; 514 *rp = r; |
|
512} 513 514void 515route_Delete(struct sticky_route **rp, int type, struct in_addr dst) 516{ 517 struct sticky_route *r; 518 int dsttype = type & ROUTE_DSTANY; 519 --- 16 unchanged lines hidden (view full) --- 536 for (r = *rp; r; r = rn) { 537 rn = r->next; 538 free(r); 539 } 540 *rp = NULL; 541} 542 543void | 515} 516 517void 518route_Delete(struct sticky_route **rp, int type, struct in_addr dst) 519{ 520 struct sticky_route *r; 521 int dsttype = type & ROUTE_DSTANY; 522 --- 16 unchanged lines hidden (view full) --- 539 for (r = *rp; r; r = rn) { 540 rn = r->next; 541 free(r); 542 } 543 *rp = NULL; 544} 545 546void |
544route_ShowSticky(struct prompt *p, struct sticky_route *r) | 547route_ShowSticky(struct prompt *p, struct sticky_route *r, const char *tag, 548 int indent) |
545{ 546 int def; | 549{ 550 int def; |
551 int tlen = strlen(tag); |
|
547 | 552 |
548 prompt_Printf(p, "Sticky routes:\n"); | 553 if (tlen + 2 > indent) 554 prompt_Printf(p, "%s:\n%*s", tag, indent, ""); 555 else 556 prompt_Printf(p, "%s:%*s", tag, indent - tlen - 1, ""); 557 |
549 for (; r; r = r->next) { 550 def = r->dst.s_addr == INADDR_ANY && r->mask.s_addr == INADDR_ANY; 551 | 558 for (; r; r = r->next) { 559 def = r->dst.s_addr == INADDR_ANY && r->mask.s_addr == INADDR_ANY; 560 |
552 prompt_Printf(p, " add "); | 561 prompt_Printf(p, "%*sadd ", tlen ? 0 : indent, ""); 562 tlen = 0; |
553 if (r->type & ROUTE_DSTMYADDR) 554 prompt_Printf(p, "MYADDR"); 555 else if (r->type & ROUTE_DSTHISADDR) 556 prompt_Printf(p, "HISADDR"); 557 else if (!def) 558 prompt_Printf(p, "%s", inet_ntoa(r->dst)); 559 560 if (def) 561 prompt_Printf(p, "default "); 562 else 563 prompt_Printf(p, " %s ", inet_ntoa(r->mask)); 564 565 if (r->type & ROUTE_GWHISADDR) 566 prompt_Printf(p, "HISADDR\n"); 567 else 568 prompt_Printf(p, "%s\n", inet_ntoa(r->gw)); 569 } 570} | 563 if (r->type & ROUTE_DSTMYADDR) 564 prompt_Printf(p, "MYADDR"); 565 else if (r->type & ROUTE_DSTHISADDR) 566 prompt_Printf(p, "HISADDR"); 567 else if (!def) 568 prompt_Printf(p, "%s", inet_ntoa(r->dst)); 569 570 if (def) 571 prompt_Printf(p, "default "); 572 else 573 prompt_Printf(p, " %s ", inet_ntoa(r->mask)); 574 575 if (r->type & ROUTE_GWHISADDR) 576 prompt_Printf(p, "HISADDR\n"); 577 else 578 prompt_Printf(p, "%s\n", inet_ntoa(r->gw)); 579 } 580} |