Annotation of embedaddon/quagga/zebra/irdp_interface.c, revision 1.1.1.3

1.1       misho       1: /*
                      2:  *
                      3:  * Copyright (C) 2000  Robert Olsson.
                      4:  * Swedish University of Agricultural Sciences
                      5:  *
                      6:  * This file is part of GNU Zebra.
                      7:  *
                      8:  * GNU Zebra is free software; you can redistribute it and/or modify it
                      9:  * under the terms of the GNU General Public License as published by the
                     10:  * Free Software Foundation; either version 2, or (at your option) any
                     11:  * later version.
                     12:  *
                     13:  * GNU Zebra is distributed in the hope that it will be useful, but
                     14:  * WITHOUT ANY WARRANTY; without even the implied warranty of
                     15:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     16:  * General Public License for more details.
                     17:  *
                     18:  * You should have received a copy of the GNU General Public License
                     19:  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
                     20:  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
                     21:  * 02111-1307, USA.  
                     22:  */
                     23: 
                     24: /* 
                     25:  * This work includes work with the following copywrite:
                     26:  *
                     27:  * Copyright (C) 1997, 2000 Kunihiro Ishiguro
                     28:  *
                     29:  */
                     30: 
                     31: /* 
                     32:  * Thanks to Jens Låås at Swedish University of Agricultural Sciences
                     33:  * for reviewing and tests.
                     34:  */
                     35: 
                     36: 
                     37: #include <zebra.h>
                     38: 
                     39: #ifdef HAVE_IRDP 
                     40: 
                     41: #include "if.h"
                     42: #include "vty.h"
                     43: #include "sockunion.h"
                     44: #include "prefix.h"
                     45: #include "command.h"
                     46: #include "memory.h"
                     47: #include "stream.h"
                     48: #include "ioctl.h"
                     49: #include "connected.h"
                     50: #include "log.h"
                     51: #include "zclient.h"
                     52: #include "thread.h"
                     53: #include "zebra/interface.h"
                     54: #include "zebra/rtadv.h"
                     55: #include "zebra/rib.h"
                     56: #include "zebra/zserv.h"
                     57: #include "zebra/redistribute.h"
                     58: #include "zebra/irdp.h"
                     59: #include <netinet/ip_icmp.h>
                     60: #include "if.h"
                     61: #include "sockunion.h"
                     62: #include "log.h"
                     63: 
                     64: 
                     65: /* Master of threads. */
                     66: extern struct zebra_t zebrad;
                     67: 
                     68: extern int irdp_sock;
                     69: 
                     70: static const char *
                     71: inet_2a(u_int32_t a, char *b)
                     72: {
                     73:   sprintf(b, "%u.%u.%u.%u",
                     74:           (a    ) & 0xFF,
                     75:           (a>> 8) & 0xFF,
                     76:           (a>>16) & 0xFF,
                     77:           (a>>24) & 0xFF);
                     78:   return  b;
                     79: }
                     80: 
                     81: 
                     82: static struct prefix *
                     83: irdp_get_prefix(struct interface *ifp)
                     84: {
                     85:   struct listnode *node;
                     86:   struct connected *ifc;
                     87:   
                     88:   if (ifp->connected)
                     89:     for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
                     90:       return ifc->address;
                     91: 
                     92:   return NULL;
                     93: }
                     94: 
                     95: /* Join to the add/leave multicast group. */
                     96: static int
                     97: if_group (struct interface *ifp, 
                     98:          int sock, 
                     99:          u_int32_t group, 
                    100:          int add_leave)
                    101: {
                    102:   struct ip_mreq m;
                    103:   struct prefix *p;
                    104:   int ret;
                    105:   char b1[INET_ADDRSTRLEN];
                    106: 
                    107:   memset (&m, 0, sizeof (m));
                    108:   m.imr_multiaddr.s_addr = htonl (group);
                    109:   p = irdp_get_prefix(ifp);
                    110: 
                    111:   if(!p) {
                    112:         zlog_warn ("IRDP: can't get address for %s", ifp->name);
                    113:        return 1;
                    114:   }
                    115: 
                    116:   m.imr_interface = p->u.prefix4;
                    117: 
                    118:   ret = setsockopt (sock, IPPROTO_IP, add_leave,
                    119:                    (char *) &m, sizeof (struct ip_mreq));
                    120:   if (ret < 0)
                    121:     zlog_warn ("IRDP: %s can't setsockopt %s: %s",
                    122:               add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group", 
                    123:               inet_2a(group, b1),
                    124:               safe_strerror (errno));
                    125: 
                    126:   return ret;
                    127: }
                    128: 
                    129: static int
                    130: if_add_group (struct interface *ifp)
                    131: {
                    132:   struct zebra_if *zi= ifp->info;
                    133:   struct irdp_interface *irdp = &zi->irdp;
                    134:   int ret;
                    135:   char b1[INET_ADDRSTRLEN];
                    136: 
                    137:   ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
                    138:   if (ret < 0) {
                    139:     return ret;
                    140:   }
                    141: 
                    142:   if(irdp->flags & IF_DEBUG_MISC )
                    143:     zlog_debug("IRDP: Adding group %s for %s", 
                    144:               inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
                    145:               ifp->name);
                    146:   return 0;
                    147: }
                    148: 
                    149: static int
                    150: if_drop_group (struct interface *ifp)
                    151: {
                    152:   struct zebra_if *zi= ifp->info;
                    153:   struct irdp_interface *irdp = &zi->irdp;
                    154:   int ret;
                    155:   char b1[INET_ADDRSTRLEN];
                    156: 
                    157:   ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP);
                    158:   if (ret < 0)
                    159:     return ret;
                    160: 
                    161:   if(irdp->flags & IF_DEBUG_MISC)
                    162:     zlog_debug("IRDP: Leaving group %s for %s", 
                    163:               inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
                    164:               ifp->name);
                    165:   return 0;
                    166: }
                    167: 
                    168: static void
                    169: if_set_defaults(struct interface *ifp)
                    170: {
                    171:   struct zebra_if *zi=ifp->info;
                    172:   struct irdp_interface *irdp=&zi->irdp;
                    173: 
                    174:   irdp->MaxAdvertInterval = IRDP_MAXADVERTINTERVAL;
                    175:   irdp->MinAdvertInterval = IRDP_MINADVERTINTERVAL;
                    176:   irdp->Preference = IRDP_PREFERENCE;
                    177:   irdp->Lifetime = IRDP_LIFETIME;
                    178: }
                    179: 
                    180: 
                    181: static struct Adv *Adv_new (void)
                    182: {
                    183:   return XCALLOC (MTYPE_TMP, sizeof (struct Adv));
                    184: }
                    185: 
                    186: static void
                    187: Adv_free (struct Adv *adv)
                    188: {
                    189:   XFREE (MTYPE_TMP, adv);
                    190: }
                    191: 
                    192: static void
                    193: irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
                    194: {
                    195:   struct zebra_if *zi= ifp->info;
                    196:   struct irdp_interface *irdp = &zi->irdp;
                    197:   struct listnode *node;
                    198:   struct connected *ifc;
                    199:   u_int32_t timer, seed;
                    200: 
                    201:   if (irdp->flags & IF_ACTIVE ) {
                    202:     zlog_warn("IRDP: Interface is already active %s", ifp->name);
                    203:     return;
                    204:   }
                    205:   if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
                    206:     zlog_warn("IRDP: Cannot activate interface %s (cannot create "
                    207:              "IRDP socket)", ifp->name);
                    208:     return;
                    209:   }
                    210:   irdp->flags |= IF_ACTIVE;
                    211: 
                    212:   if(!multicast) 
                    213:     irdp->flags |= IF_BROADCAST;
                    214: 
                    215:   if_add_update(ifp);
                    216: 
                    217:   if (! (ifp->flags & IFF_UP)) {
                    218:     zlog_warn("IRDP: Interface is down %s", ifp->name);
                    219:   }
                    220: 
                    221:   /* Shall we cancel if_start if if_add_group fails? */
                    222: 
                    223:   if( multicast) {
                    224:     if_add_group(ifp);
                    225:     
                    226:     if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) {
                    227:       zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name);
                    228:     }
                    229:   }
                    230: 
                    231:   if(set_defaults) 
                    232:     if_set_defaults(ifp);
                    233: 
                    234:   irdp->irdp_sent = 0;
                    235: 
                    236:   /* The spec suggests this for randomness */
                    237: 
                    238:   seed = 0;
                    239:   if( ifp->connected)
                    240:     for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
                    241:       {
                    242:         seed = ifc->address->u.prefix4.s_addr;
                    243:         break;
                    244:       }
                    245:   
                    246:   srandom(seed);
                    247:   timer =  (random () % IRDP_DEFAULT_INTERVAL) + 1; 
                    248: 
                    249:   irdp->AdvPrefList = list_new();
                    250:   irdp->AdvPrefList->del =  (void (*)(void *)) Adv_free; /* Destructor */
                    251: 
                    252: 
                    253:   /* And this for startup. Speed limit from 1991 :-). But it's OK*/
                    254: 
                    255:   if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS &&
                    256:      timer > MAX_INITIAL_ADVERT_INTERVAL ) 
                    257:          timer= MAX_INITIAL_ADVERT_INTERVAL;
                    258: 
                    259:   
                    260:   if(irdp->flags & IF_DEBUG_MISC)
                    261:     zlog_debug("IRDP: Init timer for %s set to %u", 
                    262:               ifp->name, 
                    263:               timer);
                    264: 
                    265:   irdp->t_advertise = thread_add_timer(zebrad.master, 
                    266:                                       irdp_send_thread, 
                    267:                                       ifp, 
                    268:                                       timer);
                    269: }
                    270: 
                    271: static void
                    272: irdp_if_stop(struct interface *ifp)
                    273: {
                    274:   struct zebra_if *zi=ifp->info;
                    275:   struct irdp_interface *irdp=&zi->irdp;
                    276:   
                    277:   if (irdp == NULL) {
                    278:     zlog_warn ("Interface %s structure is NULL", ifp->name);
                    279:     return;
                    280:   }
                    281: 
                    282:   if (! (irdp->flags & IF_ACTIVE )) {
                    283:     zlog_warn("Interface is not active %s", ifp->name);
                    284:     return;
                    285:   }
                    286: 
                    287:   if(! (irdp->flags & IF_BROADCAST)) 
                    288:     if_drop_group(ifp);
                    289: 
                    290:   irdp_advert_off(ifp);
                    291: 
                    292:   list_delete(irdp->AdvPrefList);
                    293:   irdp->AdvPrefList=NULL;
                    294: 
                    295:   irdp->flags = 0;
                    296: }
                    297: 
                    298: 
                    299: static void
                    300: irdp_if_shutdown(struct interface *ifp)
                    301: {
                    302:   struct zebra_if *zi= ifp->info;
                    303:   struct irdp_interface *irdp = &zi->irdp;
                    304: 
                    305:   if (irdp->flags & IF_SHUTDOWN ) {
                    306:     zlog_warn("IRDP: Interface is already shutdown %s", ifp->name);
                    307:     return;
                    308:   }
                    309: 
                    310:   irdp->flags |= IF_SHUTDOWN;
                    311:   irdp->flags &= ~IF_ACTIVE;
                    312: 
                    313:   if(! (irdp->flags & IF_BROADCAST)) 
                    314:     if_drop_group(ifp);
                    315:   
                    316:   /* Tell the hosts we are out of service */
                    317:   irdp_advert_off(ifp);
                    318: }
                    319: 
                    320: static void
                    321: irdp_if_no_shutdown(struct interface *ifp)
                    322: {
                    323:   struct zebra_if *zi= ifp->info;
                    324:   struct irdp_interface *irdp = &zi->irdp;
                    325: 
                    326:   if (! (irdp->flags & IF_SHUTDOWN )) {
                    327:     zlog_warn("IRDP: Interface is not shutdown %s", ifp->name);
                    328:     return;
                    329:   }
                    330: 
                    331:   irdp->flags &= ~IF_SHUTDOWN;
                    332: 
                    333:   irdp_if_start(ifp, irdp->flags & IF_BROADCAST? FALSE : TRUE, FALSE); 
                    334: 
                    335: }
                    336: 
                    337: 
                    338: /* Write configuration to user */
                    339: 
                    340: void irdp_config_write (struct vty *vty, struct interface *ifp)
                    341: {
                    342:   struct zebra_if *zi=ifp->info;
                    343:   struct irdp_interface *irdp=&zi->irdp;
                    344:   struct Adv *adv;
                    345:   struct listnode *node;
                    346:   char b1[INET_ADDRSTRLEN];
                    347: 
                    348:   if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {
                    349: 
                    350:     if( irdp->flags & IF_SHUTDOWN) 
                    351:       vty_out (vty, " ip irdp shutdown %s",  VTY_NEWLINE);
                    352: 
                    353:     if( irdp->flags & IF_BROADCAST) 
                    354:       vty_out (vty, " ip irdp broadcast%s",  VTY_NEWLINE);
                    355:     else 
                    356:       vty_out (vty, " ip irdp multicast%s",  VTY_NEWLINE);
                    357: 
                    358:     vty_out (vty, " ip irdp preference %ld%s",  
                    359:             irdp->Preference, VTY_NEWLINE);
                    360: 
                    361:     for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
                    362:       vty_out (vty, " ip irdp address %s preference %d%s",
                    363:                     inet_2a(adv->ip.s_addr, b1),
                    364:                     adv->pref, 
                    365:                     VTY_NEWLINE);
                    366: 
                    367:     vty_out (vty, " ip irdp holdtime %d%s",  
                    368:             irdp->Lifetime, VTY_NEWLINE);
                    369: 
                    370:     vty_out (vty, " ip irdp minadvertinterval %ld%s",  
                    371:             irdp->MinAdvertInterval, VTY_NEWLINE);
                    372: 
                    373:     vty_out (vty, " ip irdp maxadvertinterval %ld%s",  
                    374:             irdp->MaxAdvertInterval, VTY_NEWLINE);
                    375: 
                    376:   }
                    377: }
                    378: 
                    379: 
                    380: DEFUN (ip_irdp_multicast,
                    381:        ip_irdp_multicast_cmd,
                    382:        "ip irdp multicast",
                    383:        IP_STR
                    384:        "ICMP Router discovery on this interface using multicast\n")
                    385: {
                    386:   struct interface *ifp;
                    387: 
                    388:   ifp = (struct interface *) vty->index;
                    389:   if(!ifp) {
                    390:          return CMD_WARNING;
                    391:   }
                    392: 
                    393:   irdp_if_start(ifp, TRUE, TRUE);
                    394:   return CMD_SUCCESS;
                    395: }
                    396: 
                    397: DEFUN (ip_irdp_broadcast,
                    398:        ip_irdp_broadcast_cmd,
                    399:        "ip irdp broadcast",
                    400:        IP_STR
                    401:        "ICMP Router discovery on this interface using broadcast\n")
                    402: {
                    403:   struct interface *ifp;
                    404: 
                    405:   ifp = (struct interface *) vty->index;
                    406:   if(!ifp) {
                    407:          return CMD_WARNING;
                    408:   }
                    409: 
                    410:   irdp_if_start(ifp, FALSE, TRUE);
                    411:   return CMD_SUCCESS;
                    412: }
                    413: 
                    414: DEFUN (no_ip_irdp,
                    415:        no_ip_irdp_cmd,
                    416:        "no ip irdp",
                    417:        NO_STR
                    418:        IP_STR
                    419:        "Disable ICMP Router discovery on this interface\n")
                    420: {
                    421:   struct interface *ifp;
                    422: 
                    423:   ifp = (struct interface *) vty->index;
                    424:   if(!ifp) {
                    425:          return CMD_WARNING;
                    426:   }
                    427: 
                    428:   irdp_if_stop(ifp);
                    429:   return CMD_SUCCESS;
                    430: }
                    431: 
                    432: DEFUN (ip_irdp_shutdown,
                    433:        ip_irdp_shutdown_cmd,
                    434:        "ip irdp shutdown",
                    435:        IP_STR
                    436:        "ICMP Router discovery shutdown on this interface\n")
                    437: {
                    438:   struct interface *ifp;
                    439: 
                    440:   ifp = (struct interface *) vty->index;
                    441:   if(!ifp) {
                    442:          return CMD_WARNING;
                    443:   }
                    444: 
                    445:   irdp_if_shutdown(ifp);
                    446:   return CMD_SUCCESS;
                    447: }
                    448: 
                    449: DEFUN (no_ip_irdp_shutdown,
                    450:        no_ip_irdp_shutdown_cmd,
                    451:        "no ip irdp shutdown",
                    452:        NO_STR
                    453:        IP_STR
                    454:        "ICMP Router discovery no shutdown on this interface\n")
                    455: {
                    456:   struct interface *ifp;
                    457: 
                    458:   ifp = (struct interface *) vty->index;
                    459:   if(!ifp) {
                    460:          return CMD_WARNING;
                    461:   }
                    462: 
                    463:   irdp_if_no_shutdown(ifp);
                    464:   return CMD_SUCCESS;
                    465: }
                    466: 
                    467: DEFUN (ip_irdp_holdtime,
                    468:        ip_irdp_holdtime_cmd,
                    469:        "ip irdp holdtime <0-9000>",
                    470:        IP_STR
                    471:        "ICMP Router discovery on this interface\n"
                    472:        "Set holdtime value\n"
                    473:        "Holdtime value in seconds. Default is 1800 seconds\n")
                    474: {
                    475:   struct interface *ifp;
                    476:   struct zebra_if *zi;
                    477:   struct irdp_interface *irdp;
                    478:   ifp = (struct interface *) vty->index;
                    479:   if(!ifp) {
                    480:          return CMD_WARNING;
                    481:   }
                    482: 
                    483:   zi=ifp->info;
                    484:   irdp=&zi->irdp;
                    485: 
                    486:   irdp->Lifetime = atoi(argv[0]);
                    487:   return CMD_SUCCESS;
                    488: }
                    489: 
                    490: DEFUN (ip_irdp_minadvertinterval,
                    491:        ip_irdp_minadvertinterval_cmd,
                    492:        "ip irdp minadvertinterval <3-1800>",
                    493:        IP_STR
                    494:        "ICMP Router discovery on this interface\n"
                    495:        "Set minimum time between advertisement\n"
                    496:        "Minimum advertisement interval in seconds\n")
                    497: {
                    498:   struct interface *ifp;
                    499:   struct zebra_if *zi;
                    500:   struct irdp_interface *irdp;
                    501:   ifp = (struct interface *) vty->index;
                    502:   if(!ifp) {
                    503:          return CMD_WARNING;
                    504:   }
                    505: 
                    506:   zi=ifp->info;
                    507:   irdp=&zi->irdp;
                    508: 
                    509:   if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) {
                    510:       irdp->MinAdvertInterval = atoi(argv[0]);
                    511: 
                    512:       return CMD_SUCCESS;
                    513:   }
                    514: 
                    515:   vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", 
                    516:             VTY_NEWLINE);
                    517: 
                    518:   vty_out (vty, "Please correct!%s", 
                    519:             VTY_NEWLINE);
                    520:   return CMD_WARNING;
                    521: }
                    522: 
                    523: DEFUN (ip_irdp_maxadvertinterval,
                    524:        ip_irdp_maxadvertinterval_cmd,
                    525:        "ip irdp maxadvertinterval <4-1800>",
                    526:        IP_STR
                    527:        "ICMP Router discovery on this interface\n"
                    528:        "Set maximum time between advertisement\n"
                    529:        "Maximum advertisement interval in seconds\n")
                    530: {
                    531:   struct interface *ifp;
                    532:   struct zebra_if *zi;
                    533:   struct irdp_interface *irdp;
                    534:   ifp = (struct interface *) vty->index;
                    535:   if(!ifp) {
                    536:          return CMD_WARNING;
                    537:   }
                    538: 
                    539:   zi=ifp->info;
                    540:   irdp=&zi->irdp;
                    541: 
                    542: 
                    543:   if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) {
                    544:     irdp->MaxAdvertInterval = atoi(argv[0]);
                    545: 
                    546:       return CMD_SUCCESS;
                    547:   }
                    548: 
                    549:   vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", 
                    550:             VTY_NEWLINE);
                    551: 
                    552:   vty_out (vty, "Please correct!%s", 
                    553:             VTY_NEWLINE);
                    554:   return CMD_WARNING;
                    555: }
                    556: 
                    557: /* DEFUN needs to be fixed for negative ranages...
                    558:  * "ip irdp preference <-2147483648-2147483647>",
                    559:  * Be positive for now. :-)
                    560:  */
                    561: 
                    562: DEFUN (ip_irdp_preference,
                    563:        ip_irdp_preference_cmd,
                    564:        "ip irdp preference <0-2147483647>",
                    565:        IP_STR
                    566:        "ICMP Router discovery on this interface\n"
                    567:        "Set default preference level for this interface\n"
                    568:        "Preference level\n")
                    569: {
                    570:   struct interface *ifp;
                    571:   struct zebra_if *zi;
                    572:   struct irdp_interface *irdp;
                    573:   ifp = (struct interface *) vty->index;
                    574:   if(!ifp) {
                    575:          return CMD_WARNING;
                    576:   }
                    577: 
                    578:   zi=ifp->info;
                    579:   irdp=&zi->irdp;
                    580: 
                    581:   irdp->Preference = atoi(argv[0]);
                    582:   return CMD_SUCCESS;
                    583: }
                    584: 
                    585: DEFUN (ip_irdp_address_preference,
                    586:        ip_irdp_address_preference_cmd,
                    587:        "ip irdp address A.B.C.D preference <0-2147483647>",
                    588:        IP_STR
                    589:        "Alter ICMP Router discovery preference this interface\n"
                    590:        "Specify IRDP non-default preference to advertise\n"
                    591:        "Set IRDP address for advertise\n"
                    592:        "Preference level\n")
                    593: {
                    594:   struct listnode *node;
                    595:   struct in_addr ip; 
                    596:   int pref;
                    597:   int ret;
                    598:   struct interface *ifp;
                    599:   struct zebra_if *zi;
                    600:   struct irdp_interface *irdp;
                    601:   struct Adv *adv;
                    602: 
                    603:   ifp = (struct interface *) vty->index;
                    604:   if(!ifp) {
                    605:          return CMD_WARNING;
                    606:   }
                    607: 
                    608:   zi=ifp->info;
                    609:   irdp=&zi->irdp;
                    610: 
                    611:   ret = inet_aton(argv[0], &ip);
                    612:   if(!ret) return CMD_WARNING;
                    613: 
                    614:   pref = atoi(argv[1]);
                    615: 
                    616:   for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
                    617:     if(adv->ip.s_addr == ip.s_addr) 
                    618:       return CMD_SUCCESS;
                    619: 
                    620:   adv = Adv_new();
                    621:   adv->ip = ip;
                    622:   adv->pref = pref;
                    623:   listnode_add(irdp->AdvPrefList, adv);
                    624: 
                    625:   return CMD_SUCCESS;
                    626: 
                    627: }
                    628: 
                    629: DEFUN (no_ip_irdp_address_preference,
                    630:        no_ip_irdp_address_preference_cmd,
                    631:        "no ip irdp address A.B.C.D preference <0-2147483647>",
                    632:        NO_STR
                    633:        IP_STR
                    634:        "Alter ICMP Router discovery preference this interface\n"
                    635:        "Removes IRDP non-default preference\n"
                    636:        "Select IRDP address\n"
                    637:        "Old preference level\n")
                    638: {
                    639:   struct listnode *node, *nnode;
                    640:   struct in_addr ip; 
                    641:   int ret;
                    642:   struct interface *ifp;
                    643:   struct zebra_if *zi;
                    644:   struct irdp_interface *irdp;
                    645:   struct Adv *adv;
                    646: 
                    647:   ifp = (struct interface *) vty->index;
                    648:   if(!ifp) {
                    649:          return CMD_WARNING;
                    650:   }
                    651: 
                    652:   zi=ifp->info;
                    653:   irdp=&zi->irdp;
                    654: 
                    655:   ret = inet_aton(argv[0], &ip);
                    656:   if (!ret) 
                    657:     return CMD_WARNING;
                    658: 
                    659:   for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv))
                    660:     {
                    661:       if(adv->ip.s_addr == ip.s_addr )
                    662:         {
                    663:           listnode_delete(irdp->AdvPrefList, adv);
                    664:           break;
                    665:         }
                    666:     }
                    667:   
                    668:   return CMD_SUCCESS;
                    669: }
                    670: 
                    671: DEFUN (ip_irdp_debug_messages,
                    672:        ip_irdp_debug_messages_cmd,
                    673:        "ip irdp debug messages",
                    674:        IP_STR
                    675:        "ICMP Router discovery debug Averts. and Solicits (short)\n")
                    676: {
                    677:   struct interface *ifp;
                    678:   struct zebra_if *zi;
                    679:   struct irdp_interface *irdp;
                    680:   ifp = (struct interface *) vty->index;
                    681:   if(!ifp) {
                    682:          return CMD_WARNING;
                    683:   }
                    684: 
                    685:   zi=ifp->info;
                    686:   irdp=&zi->irdp;
                    687: 
                    688:   irdp->flags |= IF_DEBUG_MESSAGES;
                    689: 
                    690:   return CMD_SUCCESS;
                    691: }
                    692: 
                    693: DEFUN (ip_irdp_debug_misc,
                    694:        ip_irdp_debug_misc_cmd,
                    695:        "ip irdp debug misc",
                    696:        IP_STR
                    697:        "ICMP Router discovery debug Averts. and Solicits (short)\n")
                    698: {
                    699:   struct interface *ifp;
                    700:   struct zebra_if *zi;
                    701:   struct irdp_interface *irdp;
                    702:   ifp = (struct interface *) vty->index;
                    703:   if(!ifp) {
                    704:          return CMD_WARNING;
                    705:   }
                    706: 
                    707:   zi=ifp->info;
                    708:   irdp=&zi->irdp;
                    709: 
                    710:   irdp->flags |= IF_DEBUG_MISC;
                    711: 
                    712:   return CMD_SUCCESS;
                    713: }
                    714: 
                    715: DEFUN (ip_irdp_debug_packet,
                    716:        ip_irdp_debug_packet_cmd,
                    717:        "ip irdp debug packet",
                    718:        IP_STR
                    719:        "ICMP Router discovery debug Averts. and Solicits (short)\n")
                    720: {
                    721:   struct interface *ifp;
                    722:   struct zebra_if *zi;
                    723:   struct irdp_interface *irdp;
                    724:   ifp = (struct interface *) vty->index;
                    725:   if(!ifp) {
                    726:          return CMD_WARNING;
                    727:   }
                    728: 
                    729:   zi=ifp->info;
                    730:   irdp=&zi->irdp;
                    731: 
                    732:   irdp->flags |= IF_DEBUG_PACKET;
                    733: 
                    734:   return CMD_SUCCESS;
                    735: }
                    736: 
                    737: 
                    738: DEFUN (ip_irdp_debug_disable,
                    739:        ip_irdp_debug_disable_cmd,
                    740:        "ip irdp debug disable",
                    741:        IP_STR
                    742:        "ICMP Router discovery debug Averts. and Solicits (short)\n")
                    743: {
                    744:   struct interface *ifp;
                    745:   struct zebra_if *zi;
                    746:   struct irdp_interface *irdp;
                    747:   ifp = (struct interface *) vty->index;
                    748:   if(!ifp) {
                    749:          return CMD_WARNING;
                    750:   }
                    751: 
                    752:   zi=ifp->info;
                    753:   irdp=&zi->irdp;
                    754: 
                    755:   irdp->flags &= ~IF_DEBUG_PACKET;
                    756:   irdp->flags &= ~IF_DEBUG_MESSAGES;
                    757:   irdp->flags &= ~IF_DEBUG_MISC;
                    758: 
                    759:   return CMD_SUCCESS;
                    760: }
                    761: 
                    762: void
                    763: irdp_init ()
                    764: {
                    765:   install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd);
                    766:   install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd);
                    767:   install_element (INTERFACE_NODE, &no_ip_irdp_cmd);
                    768:   install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd);
                    769:   install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd);
                    770:   install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd);
                    771:   install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd);
                    772:   install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd);
                    773:   install_element (INTERFACE_NODE, &ip_irdp_preference_cmd);
                    774:   install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd);
                    775:   install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd);
                    776: 
                    777:   install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd);
                    778:   install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd);
                    779:   install_element (INTERFACE_NODE, &ip_irdp_debug_packet_cmd);
                    780:   install_element (INTERFACE_NODE, &ip_irdp_debug_disable_cmd);
                    781: }
                    782: 
                    783: #endif /* HAVE_IRDP */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>