Annotation of embedaddon/quagga/ospf6d/ospf6_zebra.c, revision 1.1.1.3

1.1       misho       1: /*
                      2:  * Copyright (C) 2003 Yasuhiro Ohara
                      3:  *
                      4:  * This file is part of GNU Zebra.
                      5:  *
                      6:  * GNU Zebra is free software; you can redistribute it and/or modify it
                      7:  * under the terms of the GNU General Public License as published by the
                      8:  * Free Software Foundation; either version 2, or (at your option) any
                      9:  * later version.
                     10:  *
                     11:  * GNU Zebra is distributed in the hope that it will be useful, but
                     12:  * WITHOUT ANY WARRANTY; without even the implied warranty of
                     13:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                     14:  * General Public License for more details.
                     15:  *
                     16:  * You should have received a copy of the GNU General Public License
                     17:  * along with GNU Zebra; see the file COPYING.  If not, write to the 
                     18:  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
                     19:  * Boston, MA 02111-1307, USA.  
                     20:  */
                     21: 
                     22: #include <zebra.h>
                     23: 
                     24: #include "log.h"
                     25: #include "vty.h"
                     26: #include "command.h"
                     27: #include "prefix.h"
                     28: #include "stream.h"
                     29: #include "zclient.h"
                     30: #include "memory.h"
                     31: 
                     32: #include "ospf6_proto.h"
                     33: #include "ospf6_top.h"
                     34: #include "ospf6_interface.h"
                     35: #include "ospf6_route.h"
                     36: #include "ospf6_lsa.h"
                     37: #include "ospf6_lsdb.h"
                     38: #include "ospf6_asbr.h"
                     39: #include "ospf6_zebra.h"
                     40: #include "ospf6d.h"
                     41: 
                     42: unsigned char conf_debug_ospf6_zebra = 0;
                     43: 
                     44: /* information about zebra. */
                     45: struct zclient *zclient = NULL;
                     46: 
                     47: struct in_addr router_id_zebra;
                     48: 
                     49: /* Router-id update message from zebra. */
                     50: static int
                     51: ospf6_router_id_update_zebra (int command, struct zclient *zclient,
1.1.1.3 ! misho      52:                              zebra_size_t length, vrf_id_t vrf_id)
1.1       misho      53: {
                     54:   struct prefix router_id;
                     55:   struct ospf6 *o = ospf6;
                     56: 
                     57:   zebra_router_id_update_read(zclient->ibuf,&router_id);
                     58:   router_id_zebra = router_id.u.prefix4;
                     59: 
                     60:   if (o == NULL)
                     61:     return 0;
                     62: 
                     63:   if (o->router_id  == 0)
                     64:     o->router_id = (u_int32_t) router_id_zebra.s_addr;
                     65: 
                     66:   return 0;
                     67: }
                     68: 
                     69: /* redistribute function */
                     70: void
                     71: ospf6_zebra_redistribute (int type)
                     72: {
1.1.1.3 ! misho      73:   if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
1.1       misho      74:     return;
1.1.1.3 ! misho      75:   vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);
1.1       misho      76:   if (zclient->sock > 0)
1.1.1.3 ! misho      77:     zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type,
        !            78:                              VRF_DEFAULT);
1.1       misho      79: }
                     80: 
                     81: void
                     82: ospf6_zebra_no_redistribute (int type)
                     83: {
1.1.1.3 ! misho      84:   if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
1.1       misho      85:     return;
1.1.1.3 ! misho      86:   vrf_bitmap_unset (zclient->redist[type], VRF_DEFAULT);
1.1       misho      87:   if (zclient->sock > 0)
1.1.1.3 ! misho      88:     zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type,
        !            89:                              VRF_DEFAULT);
1.1       misho      90: }
                     91: 
                     92: /* Inteface addition message from zebra. */
                     93: static int
1.1.1.3 ! misho      94: ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length,
        !            95:     vrf_id_t vrf_id)
1.1       misho      96: {
                     97:   struct interface *ifp;
                     98: 
1.1.1.3 ! misho      99:   ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
1.1       misho     100:   if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    101:     zlog_debug ("Zebra Interface add: %s index %d mtu %d",
                    102:                ifp->name, ifp->ifindex, ifp->mtu6);
                    103:   ospf6_interface_if_add (ifp);
                    104:   return 0;
                    105: }
                    106: 
                    107: static int
1.1.1.3 ! misho     108: ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length,
        !           109:     vrf_id_t vrf_id)
1.1       misho     110: {
                    111:   struct interface *ifp;
                    112: 
1.1.1.3 ! misho     113:   if (!(ifp = zebra_interface_state_read (zclient->ibuf, vrf_id)))
1.1       misho     114:     return 0;
                    115: 
                    116:   if (if_is_up (ifp))
                    117:     zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name);
                    118: 
                    119:   if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    120:     zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
                    121:                ifp->name, ifp->ifindex, ifp->mtu6);
                    122: 
                    123: #if 0
1.1.1.3 ! misho     124:   /* XXX: ospf6_interface_if_del is not the right way to handle this,
        !           125:    * because among other thinkable issues, it will also clear all
        !           126:    * settings as they are contained in the struct ospf6_interface. */
1.1       misho     127:   ospf6_interface_if_del (ifp);
                    128: #endif /*0*/
                    129: 
                    130:   ifp->ifindex = IFINDEX_INTERNAL;
                    131:   return 0;
                    132: }
                    133: 
                    134: static int
                    135: ospf6_zebra_if_state_update (int command, struct zclient *zclient,
1.1.1.3 ! misho     136:                              zebra_size_t length, vrf_id_t vrf_id)
1.1       misho     137: {
                    138:   struct interface *ifp;
                    139: 
1.1.1.3 ! misho     140:   ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
1.1       misho     141:   if (ifp == NULL)
                    142:     return 0;
                    143:   
                    144:   if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    145:     zlog_debug ("Zebra Interface state change: "
1.1.1.3 ! misho     146:                 "%s index %d flags %llx metric %d mtu %d bandwidth %d",
1.1       misho     147:                ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, 
1.1.1.3 ! misho     148:                ifp->metric, ifp->mtu6, ifp->bandwidth);
1.1       misho     149: 
                    150:   ospf6_interface_state_update (ifp);
                    151:   return 0;
                    152: }
                    153: 
                    154: static int
                    155: ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
1.1.1.3 ! misho     156:                                    zebra_size_t length, vrf_id_t vrf_id)
1.1       misho     157: {
                    158:   struct connected *c;
                    159:   char buf[128];
                    160: 
1.1.1.3 ! misho     161:   c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf,
        !           162:                                     vrf_id);
1.1       misho     163:   if (c == NULL)
                    164:     return 0;
                    165: 
                    166:   if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    167:     zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
                    168:                c->ifp->name, prefix_family_str (c->address),
                    169:                inet_ntop (c->address->family, &c->address->u.prefix,
                    170:                           buf, sizeof (buf)), c->address->prefixlen);
                    171: 
                    172:   if (c->address->family == AF_INET6)
1.1.1.3 ! misho     173:     {
        !           174:       ospf6_interface_state_update (c->ifp);
        !           175:       ospf6_interface_connected_route_update (c->ifp);
        !           176:     }
1.1       misho     177:   return 0;
                    178: }
                    179: 
                    180: static int
                    181: ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
1.1.1.3 ! misho     182:                                zebra_size_t length, vrf_id_t vrf_id)
1.1       misho     183: {
                    184:   struct connected *c;
                    185:   char buf[128];
                    186: 
1.1.1.3 ! misho     187:   c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf,
        !           188:                                     vrf_id);
1.1       misho     189:   if (c == NULL)
                    190:     return 0;
                    191: 
                    192:   if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    193:     zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
                    194:                c->ifp->name, prefix_family_str (c->address),
                    195:                inet_ntop (c->address->family, &c->address->u.prefix,
                    196:                           buf, sizeof (buf)), c->address->prefixlen);
                    197: 
                    198:   if (c->address->family == AF_INET6)
1.1.1.3 ! misho     199:     {
        !           200:       ospf6_interface_connected_route_update (c->ifp);
        !           201:       ospf6_interface_state_update (c->ifp);
        !           202:     }
1.1       misho     203: 
                    204:   return 0;
                    205: }
                    206: 
                    207: static int
                    208: ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
1.1.1.3 ! misho     209:                        zebra_size_t length, vrf_id_t vrf_id)
1.1       misho     210: {
                    211:   struct stream *s;
                    212:   struct zapi_ipv6 api;
                    213:   unsigned long ifindex;
                    214:   struct prefix_ipv6 p;
                    215:   struct in6_addr *nexthop;
1.1.1.3 ! misho     216:   unsigned char plength = 0;
1.1       misho     217: 
                    218:   s = zclient->ibuf;
                    219:   ifindex = 0;
                    220:   nexthop = NULL;
                    221:   memset (&api, 0, sizeof (api));
                    222: 
                    223:   /* Type, flags, message. */
                    224:   api.type = stream_getc (s);
                    225:   api.flags = stream_getc (s);
                    226:   api.message = stream_getc (s);
                    227: 
                    228:   /* IPv6 prefix. */
                    229:   memset (&p, 0, sizeof (struct prefix_ipv6));
                    230:   p.family = AF_INET6;
1.1.1.3 ! misho     231:   plength = stream_getc (s);
        !           232:   p.prefixlen = MIN(IPV6_MAX_PREFIXLEN, plength);
1.1       misho     233:   stream_get (&p.prefix, s, PSIZE (p.prefixlen));
                    234: 
                    235:   /* Nexthop, ifindex, distance, metric. */
                    236:   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
                    237:     {
                    238:       api.nexthop_num = stream_getc (s);
                    239:       nexthop = (struct in6_addr *)
                    240:         malloc (api.nexthop_num * sizeof (struct in6_addr));
                    241:       stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
                    242:     }
                    243:   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
                    244:     {
                    245:       api.ifindex_num = stream_getc (s);
                    246:       ifindex = stream_getl (s);
                    247:     }
                    248:   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
                    249:     api.distance = stream_getc (s);
                    250:   else
                    251:     api.distance = 0;
                    252:   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
                    253:     api.metric = stream_getl (s);
                    254:   else
                    255:     api.metric = 0;
                    256: 
                    257:   if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    258:     {
                    259:       char prefixstr[128], nexthopstr[128];
                    260:       prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
                    261:       if (nexthop)
                    262:         inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
                    263:       else
                    264:         snprintf (nexthopstr, sizeof (nexthopstr), "::");
                    265: 
                    266:       zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
                    267:                  (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
                    268:                  zebra_route_string(api.type), prefixstr, nexthopstr, ifindex);
                    269:     }
                    270:  
                    271:   if (command == ZEBRA_IPV6_ROUTE_ADD)
                    272:     ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
                    273:                                  api.nexthop_num, nexthop);
                    274:   else
                    275:     ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
                    276: 
                    277:   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
                    278:     free (nexthop);
                    279: 
                    280:   return 0;
                    281: }
                    282: 
                    283: 
                    284: 
1.1.1.3 ! misho     285: 
1.1       misho     286: DEFUN (show_zebra,
                    287:        show_zebra_cmd,
                    288:        "show zebra",
                    289:        SHOW_STR
                    290:        "Zebra information\n")
                    291: {
                    292:   int i;
                    293:   if (zclient == NULL)
                    294:     {
                    295:       vty_out (vty, "Not connected to zebra%s", VNL);
                    296:       return CMD_SUCCESS;
                    297:     }
                    298: 
                    299:   vty_out (vty, "Zebra Infomation%s", VNL);
                    300:   vty_out (vty, "  enable: %d fail: %d%s",
                    301:            zclient->enable, zclient->fail, VNL);
1.1.1.3 ! misho     302:   vty_out (vty, "  redistribute default: %d%s",
        !           303:            vrf_bitmap_check (zclient->default_information, VRF_DEFAULT),
1.1       misho     304:            VNL);
                    305:   vty_out (vty, "  redistribute:");
                    306:   for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
                    307:     {
1.1.1.3 ! misho     308:       if (vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT))
1.1       misho     309:         vty_out (vty, " %s", zebra_route_string(i));
                    310:     }
                    311:   vty_out (vty, "%s", VNL);
                    312:   return CMD_SUCCESS;
                    313: }
                    314: 
                    315: DEFUN (router_zebra,
                    316:        router_zebra_cmd,
                    317:        "router zebra",
                    318:        "Enable a routing process\n"
                    319:        "Make connection to zebra daemon\n")
                    320: {
                    321:   vty->node = ZEBRA_NODE;
                    322:   zclient->enable = 1;
                    323:   zclient_start (zclient);
                    324:   return CMD_SUCCESS;
                    325: }
                    326: 
                    327: DEFUN (no_router_zebra,
                    328:        no_router_zebra_cmd,
                    329:        "no router zebra",
                    330:        NO_STR
                    331:        "Configure routing process\n"
                    332:        "Disable connection to zebra daemon\n")
                    333: {
                    334:   zclient->enable = 0;
                    335:   zclient_stop (zclient);
                    336:   return CMD_SUCCESS;
                    337: }
                    338: 
                    339: /* Zebra configuration write function. */
                    340: static int
                    341: config_write_ospf6_zebra (struct vty *vty)
                    342: {
                    343:   if (! zclient->enable)
                    344:     {
                    345:       vty_out (vty, "no router zebra%s", VNL);
                    346:       vty_out (vty, "!%s", VNL);
                    347:     }
1.1.1.3 ! misho     348:   else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
1.1       misho     349:     {
                    350:       vty_out (vty, "router zebra%s", VNL);
                    351:       vty_out (vty, " no redistribute ospf6%s", VNL);
                    352:       vty_out (vty, "!%s", VNL);
                    353:     }
                    354:   return 0;
                    355: }
                    356: 
                    357: /* Zebra node structure. */
                    358: static struct cmd_node zebra_node =
                    359: {
                    360:   ZEBRA_NODE,
                    361:   "%s(config-zebra)# ",
                    362: };
                    363: 
                    364: #define ADD    0
                    365: #define REM    1
                    366: static void
                    367: ospf6_zebra_route_update (int type, struct ospf6_route *request)
                    368: {
                    369:   struct zapi_ipv6 api;
                    370:   char buf[64];
                    371:   int nhcount;
                    372:   struct in6_addr **nexthops;
1.1.1.3 ! misho     373:   ifindex_t *ifindexes;
1.1       misho     374:   int i, ret = 0;
                    375:   struct prefix_ipv6 *dest;
                    376: 
                    377:   if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    378:     {
                    379:       prefix2str (&request->prefix, buf, sizeof (buf));
                    380:       zlog_debug ("Send %s route: %s",
                    381:                  (type == REM ? "remove" : "add"), buf);
                    382:     }
                    383: 
                    384:   if (zclient->sock < 0)
                    385:     {
                    386:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    387:         zlog_debug ("  Not connected to Zebra");
                    388:       return;
                    389:     }
                    390: 
                    391:   if (request->path.origin.adv_router == ospf6->router_id &&
                    392:       (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
                    393:        request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
                    394:     {
                    395:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    396:         zlog_debug ("  Ignore self-originated external route");
                    397:       return;
                    398:     }
                    399: 
                    400:   /* If removing is the best path and if there's another path,
                    401:      treat this request as add the secondary path */
                    402:   if (type == REM && ospf6_route_is_best (request) &&
                    403:       request->next && ospf6_route_is_same (request, request->next))
                    404:     {
                    405:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    406:         zlog_debug ("  Best-path removal resulted Sencondary addition");
                    407:       type = ADD;
                    408:       request = request->next;
                    409:     }
                    410: 
                    411:   /* Only the best path will be sent to zebra. */
                    412:   if (! ospf6_route_is_best (request))
                    413:     {
                    414:       /* this is not preferred best route, ignore */
                    415:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    416:         zlog_debug ("  Ignore non-best route");
                    417:       return;
                    418:     }
                    419: 
                    420:   nhcount = 0;
                    421:   for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
                    422:     if (ospf6_nexthop_is_set (&request->nexthop[i]))
                    423:       nhcount++;
                    424: 
                    425:   if (nhcount == 0)
                    426:     {
                    427:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    428:         zlog_debug ("  No nexthop, ignore");
                    429:       return;
                    430:     }
                    431: 
                    432:   /* allocate memory for nexthop_list */
                    433:   nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
                    434:                       nhcount * sizeof (struct in6_addr *));
                    435:   if (nexthops == NULL)
                    436:     {
                    437:       zlog_warn ("Can't send route to zebra: malloc failed");
                    438:       return;
                    439:     }
                    440: 
                    441:   /* allocate memory for ifindex_list */
                    442:   ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
                    443:                        nhcount * sizeof (unsigned int));
                    444:   if (ifindexes == NULL)
                    445:     {
                    446:       zlog_warn ("Can't send route to zebra: malloc failed");
                    447:       XFREE (MTYPE_OSPF6_OTHER, nexthops);
                    448:       return;
                    449:     }
                    450: 
                    451:   for (i = 0; i < nhcount; i++)
                    452:     {
                    453:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    454:        {
1.1.1.3 ! misho     455:          const char *ifname;
1.1       misho     456:          inet_ntop (AF_INET6, &request->nexthop[i].address,
                    457:                     buf, sizeof (buf));
1.1.1.3 ! misho     458:          ifname = ifindex2ifname (request->nexthop[i].ifindex);
1.1       misho     459:          zlog_debug ("  nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname,
                    460:                      request->nexthop[i].ifindex);
                    461:        }
                    462:       nexthops[i] = &request->nexthop[i].address;
                    463:       ifindexes[i] = request->nexthop[i].ifindex;
                    464:     }
                    465: 
1.1.1.3 ! misho     466:   api.vrf_id = VRF_DEFAULT;
1.1       misho     467:   api.type = ZEBRA_ROUTE_OSPF6;
                    468:   api.flags = 0;
                    469:   api.message = 0;
1.1.1.2   misho     470:   api.safi = SAFI_UNICAST;
1.1       misho     471:   SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
                    472:   api.nexthop_num = nhcount;
                    473:   api.nexthop = nexthops;
                    474:   SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
                    475:   api.ifindex_num = nhcount;
                    476:   api.ifindex = ifindexes;
                    477:   SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
                    478:   api.metric = (request->path.metric_type == 2 ?
                    479:                 request->path.cost_e2 : request->path.cost);
                    480: 
                    481:   dest = (struct prefix_ipv6 *) &request->prefix;
                    482:   if (type == REM)
                    483:     ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
                    484:   else
                    485:     ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
                    486: 
                    487:   if (ret < 0)
                    488:     zlog_err ("zapi_ipv6_route() %s failed: %s",
                    489:               (type == REM ? "delete" : "add"), safe_strerror (errno));
                    490: 
                    491:   XFREE (MTYPE_OSPF6_OTHER, nexthops);
                    492:   XFREE (MTYPE_OSPF6_OTHER, ifindexes);
                    493: 
                    494:   return;
                    495: }
                    496: 
                    497: void
                    498: ospf6_zebra_route_update_add (struct ospf6_route *request)
                    499: {
1.1.1.3 ! misho     500:   if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
1.1       misho     501:     {
                    502:       ospf6->route_table->hook_add = NULL;
                    503:       ospf6->route_table->hook_remove = NULL;
                    504:       return;
                    505:     }
                    506:   ospf6_zebra_route_update (ADD, request);
                    507: }
                    508: 
                    509: void
                    510: ospf6_zebra_route_update_remove (struct ospf6_route *request)
                    511: {
1.1.1.3 ! misho     512:   if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
1.1       misho     513:     {
                    514:       ospf6->route_table->hook_add = NULL;
                    515:       ospf6->route_table->hook_remove = NULL;
                    516:       return;
                    517:     }
                    518:   ospf6_zebra_route_update (REM, request);
                    519: }
                    520: 
                    521: DEFUN (redistribute_ospf6,
                    522:        redistribute_ospf6_cmd,
                    523:        "redistribute ospf6",
                    524:        "Redistribute control\n"
                    525:        "OSPF6 route\n")
                    526: {
                    527:   struct ospf6_route *route;
                    528: 
1.1.1.3 ! misho     529:   if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
1.1       misho     530:     return CMD_SUCCESS;
                    531: 
1.1.1.3 ! misho     532:   vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
1.1       misho     533: 
                    534:   if (ospf6 == NULL)
                    535:     return CMD_SUCCESS;
                    536: 
                    537:   /* send ospf6 route to zebra route table */
                    538:   for (route = ospf6_route_head (ospf6->route_table); route;
                    539:        route = ospf6_route_next (route))
                    540:     ospf6_zebra_route_update_add (route);
                    541: 
                    542:   ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
                    543:   ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
                    544: 
                    545:   return CMD_SUCCESS;
                    546: }
                    547: 
                    548: DEFUN (no_redistribute_ospf6,
                    549:        no_redistribute_ospf6_cmd,
                    550:        "no redistribute ospf6",
                    551:        NO_STR
                    552:        "Redistribute control\n"
                    553:        "OSPF6 route\n")
                    554: {
                    555:   struct ospf6_route *route;
                    556: 
1.1.1.3 ! misho     557:   if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
1.1       misho     558:     return CMD_SUCCESS;
                    559: 
1.1.1.3 ! misho     560:   vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
1.1       misho     561: 
                    562:   if (ospf6 == NULL)
                    563:     return CMD_SUCCESS;
                    564: 
                    565:   ospf6->route_table->hook_add = NULL;
                    566:   ospf6->route_table->hook_remove = NULL;
                    567: 
                    568:   /* withdraw ospf6 route from zebra route table */
                    569:   for (route = ospf6_route_head (ospf6->route_table); route;
                    570:        route = ospf6_route_next (route))
                    571:     ospf6_zebra_route_update_remove (route);
                    572: 
                    573:   return CMD_SUCCESS;
                    574: }
                    575: 
1.1.1.3 ! misho     576: static void
        !           577: ospf6_zebra_connected (struct zclient *zclient)
        !           578: {
        !           579:   zclient_send_requests (zclient, VRF_DEFAULT);
        !           580: }
        !           581: 
1.1       misho     582: void
1.1.1.3 ! misho     583: ospf6_zebra_init (struct thread_master *master)
1.1       misho     584: {
                    585:   /* Allocate zebra structure. */
1.1.1.3 ! misho     586:   zclient = zclient_new (master);
1.1       misho     587:   zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
1.1.1.3 ! misho     588:   zclient->zebra_connected = ospf6_zebra_connected;
1.1       misho     589:   zclient->router_id_update = ospf6_router_id_update_zebra;
                    590:   zclient->interface_add = ospf6_zebra_if_add;
                    591:   zclient->interface_delete = ospf6_zebra_if_del;
                    592:   zclient->interface_up = ospf6_zebra_if_state_update;
                    593:   zclient->interface_down = ospf6_zebra_if_state_update;
                    594:   zclient->interface_address_add = ospf6_zebra_if_address_update_add;
                    595:   zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
                    596:   zclient->ipv4_route_add = NULL;
                    597:   zclient->ipv4_route_delete = NULL;
                    598:   zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
                    599:   zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
                    600: 
                    601:   /* redistribute connected route by default */
                    602:   /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
                    603: 
                    604:   /* Install zebra node. */
                    605:   install_node (&zebra_node, config_write_ospf6_zebra);
                    606: 
                    607:   /* Install command element for zebra node. */
                    608:   install_element (VIEW_NODE, &show_zebra_cmd);
                    609:   install_element (ENABLE_NODE, &show_zebra_cmd);
                    610:   install_element (CONFIG_NODE, &router_zebra_cmd);
                    611:   install_element (CONFIG_NODE, &no_router_zebra_cmd);
                    612: 
                    613:   install_default (ZEBRA_NODE);
                    614:   install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
                    615:   install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
                    616: 
                    617:   return;
                    618: }
                    619: 
                    620: /* Debug */
1.1.1.3 ! misho     621: 
1.1       misho     622: DEFUN (debug_ospf6_zebra_sendrecv,
                    623:        debug_ospf6_zebra_sendrecv_cmd,
                    624:        "debug ospf6 zebra (send|recv)",
                    625:        DEBUG_STR
                    626:        OSPF6_STR
                    627:        "Debug connection between zebra\n"
                    628:        "Debug Sending zebra\n"
                    629:        "Debug Receiving zebra\n"
                    630:       )
                    631: {
                    632:   unsigned char level = 0;
                    633: 
                    634:   if (argc)
                    635:     {
                    636:       if (! strncmp (argv[0], "s", 1))
                    637:         level = OSPF6_DEBUG_ZEBRA_SEND;
                    638:       else if (! strncmp (argv[0], "r", 1))
                    639:         level = OSPF6_DEBUG_ZEBRA_RECV;
                    640:     }
                    641:   else
                    642:     level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
                    643: 
                    644:   OSPF6_DEBUG_ZEBRA_ON (level);
                    645:   return CMD_SUCCESS;
                    646: }
                    647: 
                    648: ALIAS (debug_ospf6_zebra_sendrecv,
                    649:        debug_ospf6_zebra_cmd,
                    650:        "debug ospf6 zebra",
                    651:        DEBUG_STR
                    652:        OSPF6_STR
                    653:        "Debug connection between zebra\n"
                    654:       )
                    655: 
                    656: 
                    657: DEFUN (no_debug_ospf6_zebra_sendrecv,
                    658:        no_debug_ospf6_zebra_sendrecv_cmd,
                    659:        "no debug ospf6 zebra (send|recv)",
                    660:        NO_STR
                    661:        DEBUG_STR
                    662:        OSPF6_STR
                    663:        "Debug connection between zebra\n"
                    664:        "Debug Sending zebra\n"
                    665:        "Debug Receiving zebra\n"
                    666:       )
                    667: {
                    668:   unsigned char level = 0;
                    669: 
                    670:   if (argc)
                    671:     {
                    672:       if (! strncmp (argv[0], "s", 1))
                    673:         level = OSPF6_DEBUG_ZEBRA_SEND;
                    674:       else if (! strncmp (argv[0], "r", 1))
                    675:         level = OSPF6_DEBUG_ZEBRA_RECV;
                    676:     }
                    677:   else
                    678:     level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
                    679: 
                    680:   OSPF6_DEBUG_ZEBRA_OFF (level);
                    681:   return CMD_SUCCESS;
                    682: }
                    683: 
                    684: ALIAS (no_debug_ospf6_zebra_sendrecv,
                    685:        no_debug_ospf6_zebra_cmd,
                    686:        "no debug ospf6 zebra",
                    687:        NO_STR
                    688:        DEBUG_STR
                    689:        OSPF6_STR
                    690:        "Debug connection between zebra\n"
                    691:       )
                    692: 
                    693: int
                    694: config_write_ospf6_debug_zebra (struct vty *vty)
                    695: {
                    696:   if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
                    697:     vty_out (vty, "debug ospf6 zebra%s", VNL);
                    698:   else
                    699:     {
                    700:       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
                    701:         vty_out (vty, "debug ospf6 zebra send%s", VNL);
                    702:       if (IS_OSPF6_DEBUG_ZEBRA (RECV))
                    703:         vty_out (vty, "debug ospf6 zebra recv%s", VNL);
                    704:     }
                    705:   return 0;
                    706: }
                    707: 
                    708: void
                    709: install_element_ospf6_debug_zebra (void)
                    710: {
                    711:   install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
                    712:   install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
                    713:   install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
                    714:   install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
                    715:   install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
                    716:   install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
                    717:   install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
                    718:   install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
                    719: }
                    720: 
                    721: 

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