LCOV - code coverage report
Current view: top level - zebra - irdp_interface.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 306 5.6 %
Date: 2015-11-19 Functions: 1 29 3.4 %

          Line data    Source code
       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           0 : inet_2a(u_int32_t a, char *b)
      72             : {
      73           0 :   sprintf(b, "%u.%u.%u.%u",
      74             :           (a    ) & 0xFF,
      75           0 :           (a>> 8) & 0xFF,
      76           0 :           (a>>16) & 0xFF,
      77             :           (a>>24) & 0xFF);
      78           0 :   return  b;
      79             : }
      80             : 
      81             : 
      82             : static struct prefix *
      83           0 : irdp_get_prefix(struct interface *ifp)
      84             : {
      85             :   struct listnode *node;
      86             :   struct connected *ifc;
      87             :   
      88           0 :   if (ifp->connected)
      89           0 :     for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
      90           0 :       return ifc->address;
      91             : 
      92           0 :   return NULL;
      93             : }
      94             : 
      95             : /* Join to the add/leave multicast group. */
      96             : static int
      97           0 : 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           0 :   memset (&m, 0, sizeof (m));
     108           0 :   m.imr_multiaddr.s_addr = htonl (group);
     109           0 :   p = irdp_get_prefix(ifp);
     110             : 
     111           0 :   if(!p) {
     112           0 :         zlog_warn ("IRDP: can't get address for %s", ifp->name);
     113           0 :         return 1;
     114             :   }
     115             : 
     116           0 :   m.imr_interface = p->u.prefix4;
     117             : 
     118           0 :   ret = setsockopt (sock, IPPROTO_IP, add_leave,
     119             :                     (char *) &m, sizeof (struct ip_mreq));
     120           0 :   if (ret < 0)
     121           0 :     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           0 :                safe_strerror (errno));
     125             : 
     126           0 :   return ret;
     127             : }
     128             : 
     129             : static int
     130           0 : if_add_group (struct interface *ifp)
     131             : {
     132           0 :   struct zebra_if *zi= ifp->info;
     133           0 :   struct irdp_interface *irdp = &zi->irdp;
     134             :   int ret;
     135             :   char b1[INET_ADDRSTRLEN];
     136             : 
     137           0 :   ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
     138           0 :   if (ret < 0) {
     139           0 :     return ret;
     140             :   }
     141             : 
     142           0 :   if(irdp->flags & IF_DEBUG_MISC )
     143           0 :     zlog_debug("IRDP: Adding group %s for %s", 
     144             :                inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
     145           0 :                ifp->name);
     146           0 :   return 0;
     147             : }
     148             : 
     149             : static int
     150           0 : if_drop_group (struct interface *ifp)
     151             : {
     152           0 :   struct zebra_if *zi= ifp->info;
     153           0 :   struct irdp_interface *irdp = &zi->irdp;
     154             :   int ret;
     155             :   char b1[INET_ADDRSTRLEN];
     156             : 
     157           0 :   ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP);
     158           0 :   if (ret < 0)
     159           0 :     return ret;
     160             : 
     161           0 :   if(irdp->flags & IF_DEBUG_MISC)
     162           0 :     zlog_debug("IRDP: Leaving group %s for %s", 
     163             :                inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
     164           0 :                ifp->name);
     165           0 :   return 0;
     166             : }
     167             : 
     168             : static void
     169           0 : if_set_defaults(struct interface *ifp)
     170             : {
     171           0 :   struct zebra_if *zi=ifp->info;
     172           0 :   struct irdp_interface *irdp=&zi->irdp;
     173             : 
     174           0 :   irdp->MaxAdvertInterval = IRDP_MAXADVERTINTERVAL;
     175           0 :   irdp->MinAdvertInterval = IRDP_MINADVERTINTERVAL;
     176           0 :   irdp->Preference = IRDP_PREFERENCE;
     177           0 :   irdp->Lifetime = IRDP_LIFETIME;
     178           0 : }
     179             : 
     180             : 
     181           0 : static struct Adv *Adv_new (void)
     182             : {
     183           0 :   return XCALLOC (MTYPE_TMP, sizeof (struct Adv));
     184             : }
     185             : 
     186             : static void
     187           0 : Adv_free (struct Adv *adv)
     188             : {
     189           0 :   XFREE (MTYPE_TMP, adv);
     190           0 : }
     191             : 
     192             : static void
     193           0 : irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
     194             : {
     195           0 :   struct zebra_if *zi= ifp->info;
     196           0 :   struct irdp_interface *irdp = &zi->irdp;
     197             :   struct listnode *node;
     198             :   struct connected *ifc;
     199             :   u_int32_t timer, seed;
     200             : 
     201           0 :   if (irdp->flags & IF_ACTIVE ) {
     202           0 :     zlog_warn("IRDP: Interface is already active %s", ifp->name);
     203           0 :     return;
     204             :   }
     205           0 :   if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
     206           0 :     zlog_warn("IRDP: Cannot activate interface %s (cannot create "
     207           0 :               "IRDP socket)", ifp->name);
     208           0 :     return;
     209             :   }
     210           0 :   irdp->flags |= IF_ACTIVE;
     211             : 
     212           0 :   if(!multicast) 
     213           0 :     irdp->flags |= IF_BROADCAST;
     214             : 
     215           0 :   if_add_update(ifp);
     216             : 
     217           0 :   if (! (ifp->flags & IFF_UP)) {
     218           0 :     zlog_warn("IRDP: Interface is down %s", ifp->name);
     219             :   }
     220             : 
     221             :   /* Shall we cancel if_start if if_add_group fails? */
     222             : 
     223           0 :   if( multicast) {
     224           0 :     if_add_group(ifp);
     225             :     
     226           0 :     if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) {
     227           0 :       zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name);
     228             :     }
     229             :   }
     230             : 
     231           0 :   if(set_defaults) 
     232           0 :     if_set_defaults(ifp);
     233             : 
     234           0 :   irdp->irdp_sent = 0;
     235             : 
     236             :   /* The spec suggests this for randomness */
     237             : 
     238           0 :   seed = 0;
     239           0 :   if( ifp->connected)
     240           0 :     for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
     241             :       {
     242           0 :         seed = ifc->address->u.prefix4.s_addr;
     243           0 :         break;
     244             :       }
     245             :   
     246           0 :   srandom(seed);
     247           0 :   timer =  (random () % IRDP_DEFAULT_INTERVAL) + 1; 
     248             : 
     249           0 :   irdp->AdvPrefList = list_new();
     250           0 :   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           0 :   if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS &&
     256             :      timer > MAX_INITIAL_ADVERT_INTERVAL ) 
     257           0 :           timer= MAX_INITIAL_ADVERT_INTERVAL;
     258             : 
     259             :   
     260           0 :   if(irdp->flags & IF_DEBUG_MISC)
     261           0 :     zlog_debug("IRDP: Init timer for %s set to %u", 
     262           0 :                ifp->name, 
     263             :                timer);
     264             : 
     265           0 :   irdp->t_advertise = thread_add_timer(zebrad.master, 
     266             :                                        irdp_send_thread, 
     267             :                                        ifp, 
     268             :                                        timer);
     269             : }
     270             : 
     271             : static void
     272           0 : irdp_if_stop(struct interface *ifp)
     273             : {
     274           0 :   struct zebra_if *zi=ifp->info;
     275           0 :   struct irdp_interface *irdp=&zi->irdp;
     276             :   
     277           0 :   if (irdp == NULL) {
     278           0 :     zlog_warn ("Interface %s structure is NULL", ifp->name);
     279           0 :     return;
     280             :   }
     281             : 
     282           0 :   if (! (irdp->flags & IF_ACTIVE )) {
     283           0 :     zlog_warn("Interface is not active %s", ifp->name);
     284           0 :     return;
     285             :   }
     286             : 
     287           0 :   if(! (irdp->flags & IF_BROADCAST)) 
     288           0 :     if_drop_group(ifp);
     289             : 
     290           0 :   irdp_advert_off(ifp);
     291             : 
     292           0 :   list_delete(irdp->AdvPrefList);
     293           0 :   irdp->AdvPrefList=NULL;
     294             : 
     295           0 :   irdp->flags = 0;
     296             : }
     297             : 
     298             : 
     299             : static void
     300           0 : irdp_if_shutdown(struct interface *ifp)
     301             : {
     302           0 :   struct zebra_if *zi= ifp->info;
     303           0 :   struct irdp_interface *irdp = &zi->irdp;
     304             : 
     305           0 :   if (irdp->flags & IF_SHUTDOWN ) {
     306           0 :     zlog_warn("IRDP: Interface is already shutdown %s", ifp->name);
     307           0 :     return;
     308             :   }
     309             : 
     310           0 :   irdp->flags |= IF_SHUTDOWN;
     311           0 :   irdp->flags &= ~IF_ACTIVE;
     312             : 
     313           0 :   if(! (irdp->flags & IF_BROADCAST)) 
     314           0 :     if_drop_group(ifp);
     315             :   
     316             :   /* Tell the hosts we are out of service */
     317           0 :   irdp_advert_off(ifp);
     318             : }
     319             : 
     320             : static void
     321           0 : irdp_if_no_shutdown(struct interface *ifp)
     322             : {
     323           0 :   struct zebra_if *zi= ifp->info;
     324           0 :   struct irdp_interface *irdp = &zi->irdp;
     325             : 
     326           0 :   if (! (irdp->flags & IF_SHUTDOWN )) {
     327           0 :     zlog_warn("IRDP: Interface is not shutdown %s", ifp->name);
     328           0 :     return;
     329             :   }
     330             : 
     331           0 :   irdp->flags &= ~IF_SHUTDOWN;
     332             : 
     333           0 :   irdp_if_start(ifp, irdp->flags & IF_BROADCAST? FALSE : TRUE, FALSE); 
     334             : 
     335             : }
     336             : 
     337             : 
     338             : /* Write configuration to user */
     339             : 
     340           0 : void irdp_config_write (struct vty *vty, struct interface *ifp)
     341             : {
     342           0 :   struct zebra_if *zi=ifp->info;
     343           0 :   struct irdp_interface *irdp=&zi->irdp;
     344             :   struct Adv *adv;
     345             :   struct listnode *node;
     346             :   char b1[INET_ADDRSTRLEN];
     347             : 
     348           0 :   if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {
     349             : 
     350           0 :     if( irdp->flags & IF_SHUTDOWN) 
     351           0 :       vty_out (vty, " ip irdp shutdown %s",  VTY_NEWLINE);
     352             : 
     353           0 :     if( irdp->flags & IF_BROADCAST) 
     354           0 :       vty_out (vty, " ip irdp broadcast%s",  VTY_NEWLINE);
     355             :     else 
     356           0 :       vty_out (vty, " ip irdp multicast%s",  VTY_NEWLINE);
     357             : 
     358           0 :     vty_out (vty, " ip irdp preference %ld%s",  
     359           0 :              irdp->Preference, VTY_NEWLINE);
     360             : 
     361           0 :     for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
     362           0 :       vty_out (vty, " ip irdp address %s preference %d%s",
     363             :                     inet_2a(adv->ip.s_addr, b1),
     364             :                     adv->pref, 
     365           0 :                     VTY_NEWLINE);
     366             : 
     367           0 :     vty_out (vty, " ip irdp holdtime %d%s",  
     368           0 :              irdp->Lifetime, VTY_NEWLINE);
     369             : 
     370           0 :     vty_out (vty, " ip irdp minadvertinterval %ld%s",  
     371           0 :              irdp->MinAdvertInterval, VTY_NEWLINE);
     372             : 
     373           0 :     vty_out (vty, " ip irdp maxadvertinterval %ld%s",  
     374           0 :              irdp->MaxAdvertInterval, VTY_NEWLINE);
     375             : 
     376             :   }
     377           0 : }
     378             : 
     379             : 
     380           0 : 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           0 :   ifp = (struct interface *) vty->index;
     389           0 :   if(!ifp) {
     390           0 :           return CMD_WARNING;
     391             :   }
     392             : 
     393           0 :   irdp_if_start(ifp, TRUE, TRUE);
     394           0 :   return CMD_SUCCESS;
     395             : }
     396             : 
     397           0 : 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           0 :   ifp = (struct interface *) vty->index;
     406           0 :   if(!ifp) {
     407           0 :           return CMD_WARNING;
     408             :   }
     409             : 
     410           0 :   irdp_if_start(ifp, FALSE, TRUE);
     411           0 :   return CMD_SUCCESS;
     412             : }
     413             : 
     414           0 : 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           0 :   ifp = (struct interface *) vty->index;
     424           0 :   if(!ifp) {
     425           0 :           return CMD_WARNING;
     426             :   }
     427             : 
     428           0 :   irdp_if_stop(ifp);
     429           0 :   return CMD_SUCCESS;
     430             : }
     431             : 
     432           0 : 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           0 :   ifp = (struct interface *) vty->index;
     441           0 :   if(!ifp) {
     442           0 :           return CMD_WARNING;
     443             :   }
     444             : 
     445           0 :   irdp_if_shutdown(ifp);
     446           0 :   return CMD_SUCCESS;
     447             : }
     448             : 
     449           0 : 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           0 :   ifp = (struct interface *) vty->index;
     459           0 :   if(!ifp) {
     460           0 :           return CMD_WARNING;
     461             :   }
     462             : 
     463           0 :   irdp_if_no_shutdown(ifp);
     464           0 :   return CMD_SUCCESS;
     465             : }
     466             : 
     467           0 : 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           0 :   ifp = (struct interface *) vty->index;
     479           0 :   if(!ifp) {
     480           0 :           return CMD_WARNING;
     481             :   }
     482             : 
     483           0 :   zi=ifp->info;
     484           0 :   irdp=&zi->irdp;
     485             : 
     486           0 :   irdp->Lifetime = atoi(argv[0]);
     487           0 :   return CMD_SUCCESS;
     488             : }
     489             : 
     490           0 : 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           0 :   ifp = (struct interface *) vty->index;
     502           0 :   if(!ifp) {
     503           0 :           return CMD_WARNING;
     504             :   }
     505             : 
     506           0 :   zi=ifp->info;
     507           0 :   irdp=&zi->irdp;
     508             : 
     509           0 :   if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) {
     510           0 :       irdp->MinAdvertInterval = atoi(argv[0]);
     511             : 
     512           0 :       return CMD_SUCCESS;
     513             :   }
     514             : 
     515           0 :   vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", 
     516           0 :              VTY_NEWLINE);
     517             : 
     518           0 :   vty_out (vty, "Please correct!%s", 
     519           0 :              VTY_NEWLINE);
     520           0 :   return CMD_WARNING;
     521             : }
     522             : 
     523           0 : 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           0 :   ifp = (struct interface *) vty->index;
     535           0 :   if(!ifp) {
     536           0 :           return CMD_WARNING;
     537             :   }
     538             : 
     539           0 :   zi=ifp->info;
     540           0 :   irdp=&zi->irdp;
     541             : 
     542             : 
     543           0 :   if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) {
     544           0 :     irdp->MaxAdvertInterval = atoi(argv[0]);
     545             : 
     546           0 :       return CMD_SUCCESS;
     547             :   }
     548             : 
     549           0 :   vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", 
     550           0 :              VTY_NEWLINE);
     551             : 
     552           0 :   vty_out (vty, "Please correct!%s", 
     553           0 :              VTY_NEWLINE);
     554           0 :   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           0 : 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           0 :   ifp = (struct interface *) vty->index;
     574           0 :   if(!ifp) {
     575           0 :           return CMD_WARNING;
     576             :   }
     577             : 
     578           0 :   zi=ifp->info;
     579           0 :   irdp=&zi->irdp;
     580             : 
     581           0 :   irdp->Preference = atoi(argv[0]);
     582           0 :   return CMD_SUCCESS;
     583             : }
     584             : 
     585           0 : 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           0 :   ifp = (struct interface *) vty->index;
     604           0 :   if(!ifp) {
     605           0 :           return CMD_WARNING;
     606             :   }
     607             : 
     608           0 :   zi=ifp->info;
     609           0 :   irdp=&zi->irdp;
     610             : 
     611           0 :   ret = inet_aton(argv[0], &ip);
     612           0 :   if(!ret) return CMD_WARNING;
     613             : 
     614           0 :   pref = atoi(argv[1]);
     615             : 
     616           0 :   for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
     617           0 :     if(adv->ip.s_addr == ip.s_addr) 
     618           0 :       return CMD_SUCCESS;
     619             : 
     620           0 :   adv = Adv_new();
     621           0 :   adv->ip = ip;
     622           0 :   adv->pref = pref;
     623           0 :   listnode_add(irdp->AdvPrefList, adv);
     624             : 
     625           0 :   return CMD_SUCCESS;
     626             : 
     627             : }
     628             : 
     629           0 : 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 pref;
     642             :   int ret;
     643             :   struct interface *ifp;
     644             :   struct zebra_if *zi;
     645             :   struct irdp_interface *irdp;
     646             :   struct Adv *adv;
     647             : 
     648           0 :   ifp = (struct interface *) vty->index;
     649           0 :   if(!ifp) {
     650           0 :           return CMD_WARNING;
     651             :   }
     652             : 
     653           0 :   zi=ifp->info;
     654           0 :   irdp=&zi->irdp;
     655             : 
     656           0 :   ret = inet_aton(argv[0], &ip);
     657           0 :   if (!ret) 
     658           0 :     return CMD_WARNING;
     659             : 
     660           0 :   pref = atoi(argv[1]);
     661             : 
     662           0 :   for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv))
     663             :     {
     664           0 :       if(adv->ip.s_addr == ip.s_addr )
     665             :         {
     666           0 :           listnode_delete(irdp->AdvPrefList, adv);
     667           0 :           break;
     668             :         }
     669             :     }
     670             :   
     671           0 :   return CMD_SUCCESS;
     672             : }
     673             : 
     674           0 : DEFUN (ip_irdp_debug_messages,
     675             :        ip_irdp_debug_messages_cmd,
     676             :        "ip irdp debug messages",
     677             :        IP_STR
     678             :        "ICMP Router discovery debug Averts. and Solicits (short)\n")
     679             : {
     680             :   struct interface *ifp;
     681             :   struct zebra_if *zi;
     682             :   struct irdp_interface *irdp;
     683           0 :   ifp = (struct interface *) vty->index;
     684           0 :   if(!ifp) {
     685           0 :           return CMD_WARNING;
     686             :   }
     687             : 
     688           0 :   zi=ifp->info;
     689           0 :   irdp=&zi->irdp;
     690             : 
     691           0 :   irdp->flags |= IF_DEBUG_MESSAGES;
     692             : 
     693           0 :   return CMD_SUCCESS;
     694             : }
     695             : 
     696           0 : DEFUN (ip_irdp_debug_misc,
     697             :        ip_irdp_debug_misc_cmd,
     698             :        "ip irdp debug misc",
     699             :        IP_STR
     700             :        "ICMP Router discovery debug Averts. and Solicits (short)\n")
     701             : {
     702             :   struct interface *ifp;
     703             :   struct zebra_if *zi;
     704             :   struct irdp_interface *irdp;
     705           0 :   ifp = (struct interface *) vty->index;
     706           0 :   if(!ifp) {
     707           0 :           return CMD_WARNING;
     708             :   }
     709             : 
     710           0 :   zi=ifp->info;
     711           0 :   irdp=&zi->irdp;
     712             : 
     713           0 :   irdp->flags |= IF_DEBUG_MISC;
     714             : 
     715           0 :   return CMD_SUCCESS;
     716             : }
     717             : 
     718           0 : DEFUN (ip_irdp_debug_packet,
     719             :        ip_irdp_debug_packet_cmd,
     720             :        "ip irdp debug packet",
     721             :        IP_STR
     722             :        "ICMP Router discovery debug Averts. and Solicits (short)\n")
     723             : {
     724             :   struct interface *ifp;
     725             :   struct zebra_if *zi;
     726             :   struct irdp_interface *irdp;
     727           0 :   ifp = (struct interface *) vty->index;
     728           0 :   if(!ifp) {
     729           0 :           return CMD_WARNING;
     730             :   }
     731             : 
     732           0 :   zi=ifp->info;
     733           0 :   irdp=&zi->irdp;
     734             : 
     735           0 :   irdp->flags |= IF_DEBUG_PACKET;
     736             : 
     737           0 :   return CMD_SUCCESS;
     738             : }
     739             : 
     740             : 
     741           0 : DEFUN (ip_irdp_debug_disable,
     742             :        ip_irdp_debug_disable_cmd,
     743             :        "ip irdp debug disable",
     744             :        IP_STR
     745             :        "ICMP Router discovery debug Averts. and Solicits (short)\n")
     746             : {
     747             :   struct interface *ifp;
     748             :   struct zebra_if *zi;
     749             :   struct irdp_interface *irdp;
     750           0 :   ifp = (struct interface *) vty->index;
     751           0 :   if(!ifp) {
     752           0 :           return CMD_WARNING;
     753             :   }
     754             : 
     755           0 :   zi=ifp->info;
     756           0 :   irdp=&zi->irdp;
     757             : 
     758           0 :   irdp->flags &= ~IF_DEBUG_PACKET;
     759           0 :   irdp->flags &= ~IF_DEBUG_MESSAGES;
     760           0 :   irdp->flags &= ~IF_DEBUG_MISC;
     761             : 
     762           0 :   return CMD_SUCCESS;
     763             : }
     764             : 
     765             : void
     766          45 : irdp_init ()
     767             : {
     768          45 :   install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd);
     769          45 :   install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd);
     770          45 :   install_element (INTERFACE_NODE, &no_ip_irdp_cmd);
     771          45 :   install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd);
     772          45 :   install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd);
     773          45 :   install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd);
     774          45 :   install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd);
     775          45 :   install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd);
     776          45 :   install_element (INTERFACE_NODE, &ip_irdp_preference_cmd);
     777          45 :   install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd);
     778          45 :   install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd);
     779             : 
     780          45 :   install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd);
     781          45 :   install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd);
     782          45 :   install_element (INTERFACE_NODE, &ip_irdp_debug_packet_cmd);
     783          45 :   install_element (INTERFACE_NODE, &ip_irdp_debug_disable_cmd);
     784          45 : }
     785             : 
     786             : #endif /* HAVE_IRDP */

Generated by: LCOV version 1.10