diff --git a/lib/if.c b/lib/if.c index 6ae8500291..70304e584c 100644 --- a/lib/if.c +++ b/lib/if.c @@ -840,60 +840,6 @@ ALIAS (no_interface, "Interface's name\n" VRF_CMD_HELP_STR) -DEFUN (vrf, - vrf_cmd, - "vrf NAME", - "Select a VRF to configure\n" - "VRF's name\n") -{ - struct vrf *vrfp; - size_t sl; - - if ((sl = strlen(argv[0])) > VRF_NAMSIZ) - { - vty_out (vty, "%% VRF name %s is invalid: length exceeds " - "%d characters%s", - argv[0], VRF_NAMSIZ, VTY_NEWLINE); - return CMD_WARNING; - } - - vrfp = vrf_get (VRF_UNKNOWN, argv[0]); - - VTY_PUSH_CONTEXT_COMPAT (VRF_NODE, vrfp); - - return CMD_SUCCESS; -} - -DEFUN_NOSH (no_vrf, - no_vrf_cmd, - "no vrf NAME", - NO_STR - "Delete a pseudo VRF's configuration\n" - "VRF's name\n") -{ - struct vrf *vrfp; - - vrfp = vrf_list_lookup_by_name (argv[0]); - - if (vrfp == NULL) - { - vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE); - return CMD_WARNING; - } - - if (CHECK_FLAG (vrfp->status, VRF_ACTIVE)) - { - vty_out (vty, "%% Only inactive VRFs can be deleted%s", - VTY_NEWLINE); - return CMD_WARNING; - } - - vrf_delete(vrfp); - - return CMD_SUCCESS; -} - - /* For debug purpose. */ DEFUN (show_address, show_address_cmd, diff --git a/lib/ns.c b/lib/ns.c index 07e6ec5b9a..904fc6999c 100644 --- a/lib/ns.c +++ b/lib/ns.c @@ -91,22 +91,6 @@ static int have_netns(void) #endif } -struct ns -{ - /* Identifier, same as the vector index */ - ns_id_t ns_id; - /* Name */ - char *name; - /* File descriptor */ - int fd; - - /* Master list of interfaces belonging to this NS */ - struct list *iflist; - - /* User data */ - void *info; -}; - /* Holding NS hooks */ struct ns_master { diff --git a/lib/ns.h b/lib/ns.h index c96f1b2743..74616cd62f 100644 --- a/lib/ns.h +++ b/lib/ns.h @@ -33,6 +33,22 @@ typedef u_int16_t ns_id_t; /* Default netns directory (Linux) */ #define NS_RUN_DIR "/var/run/netns" +struct ns +{ + /* Identifier, same as the vector index */ + ns_id_t ns_id; + /* Name */ + char *name; + /* File descriptor */ + int fd; + + /* Master list of interfaces belonging to this NS */ + struct list *iflist; + + /* User data */ + void *info; +}; + /* * NS hooks */ diff --git a/lib/vrf.c b/lib/vrf.c index 63adea4aec..d87e38ebe8 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -740,6 +740,60 @@ vrf_socket (int domain, int type, int protocol, vrf_id_t vrf_id) return ret; } +/* vrf CLI commands */ +DEFUN (vrf, + vrf_cmd, + "vrf NAME", + "Select a VRF to configure\n" + "VRF's name\n") +{ + struct vrf *vrfp; + size_t sl; + + if ((sl = strlen(argv[0])) > VRF_NAMSIZ) + { + vty_out (vty, "%% VRF name %s is invalid: length exceeds " + "%d characters%s", + argv[0], VRF_NAMSIZ, VTY_NEWLINE); + return CMD_WARNING; + } + + vrfp = vrf_get (VRF_UNKNOWN, argv[0]); + + VTY_PUSH_CONTEXT_COMPAT (VRF_NODE, vrfp); + + return CMD_SUCCESS; +} + +DEFUN_NOSH (no_vrf, + no_vrf_cmd, + "no vrf NAME", + NO_STR + "Delete a pseudo VRF's configuration\n" + "VRF's name\n") +{ + struct vrf *vrfp; + + vrfp = vrf_list_lookup_by_name (argv[0]); + + if (vrfp == NULL) + { + vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + + if (CHECK_FLAG (vrfp->status, VRF_ACTIVE)) + { + vty_out (vty, "%% Only inactive VRFs can be deleted%s", + VTY_NEWLINE); + return CMD_WARNING; + } + + vrf_delete(vrfp); + + return CMD_SUCCESS; +} + /* * Debug CLI for vrf's */ diff --git a/zebra/interface.c b/zebra/interface.c index 422368852d..dd1f8a146b 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1289,33 +1289,6 @@ struct cmd_node interface_node = 1 }; -/* Wrapper hook point for zebra daemon so that ifindex can be set - * DEFUN macro not used as extract.pl HAS to ignore this - * See also interface_cmd in lib/if.c - */ -DEFUN_NOSH (zebra_vrf, - zebra_vrf_cmd, - "vrf NAME", - "Select a VRF to configure\n" - "VRF's name\n") -{ - // VTY_DECLVAR_CONTEXT (vrf, vrfp); - int ret; - - /* Call lib vrf() */ - if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) - return ret; - - return ret; -} - -struct cmd_node vrf_node = -{ - VRF_NODE, - "%s(config-vrf)# ", - 1 -}; - /* Show all interfaces to vty. */ DEFUN (show_interface, show_interface_cmd, "show interface", @@ -2929,23 +2902,6 @@ if_config_write (struct vty *vty) return 0; } -static int -vrf_config_write (struct vty *vty) -{ - struct listnode *node; - struct zebra_vrf *zvrf; - - for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf)) - { - if (strcmp(zvrf->name, VRF_DEFAULT_NAME)) - { - vty_out (vty, "vrf %s%s", zvrf->name, VTY_NEWLINE); - vty_out (vty, "!%s", VTY_NEWLINE); - } - } - return 0; -} - /* Allocate and initialize interface vector. */ void zebra_if_init (void) @@ -2957,7 +2913,6 @@ zebra_if_init (void) /* Install configuration write function. */ install_node (&interface_node, if_config_write); install_node (&link_params_node, NULL); - install_node (&vrf_node, vrf_config_write); install_element (VIEW_NODE, &show_interface_cmd); install_element (VIEW_NODE, &show_interface_vrf_cmd); @@ -3020,8 +2975,4 @@ zebra_if_init (void) install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd); install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd); install_element(LINK_PARAMS_NODE, &exit_link_params_cmd); - - install_element (CONFIG_NODE, &zebra_vrf_cmd); - install_element (CONFIG_NODE, &no_vrf_cmd); - install_default (VRF_NODE); } diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 378327ab46..9f9a62f384 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -716,11 +716,18 @@ kernel_init (struct zebra_ns *zns) { unsigned long groups; - groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR; -#ifdef HAVE_IPV6 - groups |= RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR; -#endif /* HAVE_IPV6 */ + /* Initialize netlink sockets */ + groups = RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV4_IFADDR | + RTMGRP_IPV6_ROUTE | RTMGRP_IPV6_IFADDR; + + snprintf (zns->netlink.name, sizeof (zns->netlink.name), + "netlink-listen (NS %u)", zns->ns_id); + zns->netlink.sock = -1; netlink_socket (&zns->netlink, groups, zns->ns_id); + + snprintf (zns->netlink_cmd.name, sizeof (zns->netlink_cmd.name), + "netlink-cmd (NS %u)", zns->ns_id); + zns->netlink_cmd.sock = -1; netlink_socket (&zns->netlink_cmd, 0, zns->ns_id); /* Register kernel socket. */ diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 4499901021..642d2700a4 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -50,16 +50,6 @@ zebra_ns_enable (ns_id_t ns_id, void **info) rtadv_init (zns); #endif -#ifdef HAVE_NETLINK - /* Initialize netlink sockets */ - snprintf (zns->netlink.name, sizeof (zns->netlink.name), - "netlink-listen (NS %u)", ns_id); - zns->netlink.sock = -1; - - snprintf (zns->netlink_cmd.name, sizeof (zns->netlink_cmd.name), - "netlink-cmd (NS %u)", ns_id); - zns->netlink_cmd.sock = -1; -#endif zns->if_table = route_table_init (); kernel_init (zns); interface_list (zns); diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index ab825281e4..a4e5eabbc8 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -23,6 +23,7 @@ #include "log.h" #include "linklist.h" +#include "command.h" #include "memory.h" #include "zebra/debug.h" @@ -427,6 +428,50 @@ zebra_vrf_other_route_table (afi_t afi, u_int32_t table_id, vrf_id_t vrf_id) return zvrf->table[afi][SAFI_UNICAST]; } +/* Wrapper hook point for zebra daemon so that ifindex can be set + * DEFUN macro not used as extract.pl HAS to ignore this + * See also interface_cmd in lib/if.c + */ +DEFUN_NOSH (zebra_vrf, + zebra_vrf_cmd, + "vrf NAME", + "Select a VRF to configure\n" + "VRF's name\n") +{ + // VTY_DECLVAR_CONTEXT (vrf, vrfp); + int ret; + + /* Call lib vrf() */ + if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) + return ret; + + return ret; +} + +static int +vrf_config_write (struct vty *vty) +{ + struct listnode *node; + struct zebra_vrf *zvrf; + + for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf)) + { + if (strcmp(zvrf->name, VRF_DEFAULT_NAME)) + { + vty_out (vty, "vrf %s%s", zvrf->name, VTY_NEWLINE); + vty_out (vty, "!%s", VTY_NEWLINE); + } + } + return 0; +} + +struct cmd_node vrf_node = +{ + VRF_NODE, + "%s(config-vrf)# ", + 1 +}; + /* Zebra VRF initialization. */ void zebra_vrf_init (void) @@ -439,4 +484,9 @@ zebra_vrf_init (void) zvrf_list = list_new (); vrf_init (); + + install_node (&vrf_node, vrf_config_write); + install_default (VRF_NODE); + install_element (CONFIG_NODE, &zebra_vrf_cmd); + install_element (CONFIG_NODE, &no_vrf_cmd); }