2017-07-17 14:03:14 +02:00
|
|
|
/*
|
2002-12-13 21:15:29 +01:00
|
|
|
* Interface functions.
|
|
|
|
* Copyright (C) 1997, 98 Kunihiro Ishiguro
|
|
|
|
*
|
|
|
|
* This file is part of GNU Zebra.
|
2017-05-13 10:25:29 +02:00
|
|
|
*
|
2002-12-13 21:15:29 +01:00
|
|
|
* GNU Zebra is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2017-05-13 10:25:29 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-12-13 21:15:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
#include "linklist.h"
|
|
|
|
#include "vector.h"
|
2018-06-18 14:49:36 +02:00
|
|
|
#include "lib_errors.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "vty.h"
|
|
|
|
#include "command.h"
|
2015-05-22 11:39:59 +02:00
|
|
|
#include "vrf.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "if.h"
|
|
|
|
#include "sockunion.h"
|
|
|
|
#include "prefix.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "table.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "log.h"
|
2018-05-09 06:34:57 +02:00
|
|
|
#include "northbound_cli.h"
|
|
|
|
#ifndef VTYSH_EXTRACT_PL
|
|
|
|
#include "lib/if_clippy.c"
|
|
|
|
#endif
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
DEFINE_MTYPE(LIB, IF, "Interface")
|
|
|
|
DEFINE_MTYPE_STATIC(LIB, CONNECTED, "Connected")
|
|
|
|
DEFINE_MTYPE_STATIC(LIB, NBR_CONNECTED, "Neighbor Connected")
|
|
|
|
DEFINE_MTYPE(LIB, CONNECTED_LABEL, "Connected interface label")
|
|
|
|
DEFINE_MTYPE_STATIC(LIB, IF_LINK_PARAMS, "Informational Link Parameters")
|
2015-05-29 05:48:31 +02:00
|
|
|
|
2017-10-03 03:06:01 +02:00
|
|
|
static int if_cmp_func(const struct interface *, const struct interface *);
|
2017-10-03 03:06:04 +02:00
|
|
|
static int if_cmp_index_func(const struct interface *ifp1,
|
|
|
|
const struct interface *ifp2);
|
2017-10-03 03:06:01 +02:00
|
|
|
RB_GENERATE(if_name_head, interface, name_entry, if_cmp_func);
|
2017-10-03 03:06:04 +02:00
|
|
|
RB_GENERATE(if_index_head, interface, index_entry, if_cmp_index_func);
|
2017-10-03 03:06:01 +02:00
|
|
|
|
2016-09-27 14:51:08 +02:00
|
|
|
DEFINE_QOBJ_TYPE(interface)
|
|
|
|
|
2018-03-06 20:02:52 +01:00
|
|
|
DEFINE_HOOK(if_add, (struct interface * ifp), (ifp))
|
|
|
|
DEFINE_KOOH(if_del, (struct interface * ifp), (ifp))
|
2017-08-08 10:50:43 +02:00
|
|
|
|
2004-07-17 13:51:29 +02:00
|
|
|
/* Compare interface names, returning an integer greater than, equal to, or
|
|
|
|
* less than 0, (following the strcmp convention), according to the
|
|
|
|
* relationship between ifp1 and ifp2. Interface names consist of an
|
|
|
|
* alphabetic prefix and a numeric suffix. The primary sort key is
|
|
|
|
* lexicographic by name, and then numeric by number. No number sorts
|
|
|
|
* before all numbers. Examples: de0 < de1, de100 < fxp0 < xl0, devpty <
|
|
|
|
* devpty0, de0 < del0
|
2017-07-17 14:03:14 +02:00
|
|
|
*/
|
2018-09-17 18:22:59 +02:00
|
|
|
int if_cmp_name_func(const char *p1, const char *p2)
|
2003-08-01 02:24:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
unsigned int l1, l2;
|
|
|
|
long int x1, x2;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
while (*p1 && *p2) {
|
|
|
|
/* look up to any number */
|
|
|
|
l1 = strcspn(p1, "0123456789");
|
|
|
|
l2 = strcspn(p2, "0123456789");
|
|
|
|
|
|
|
|
/* name lengths are different -> compare names */
|
|
|
|
if (l1 != l2)
|
|
|
|
return (strcmp(p1, p2));
|
|
|
|
|
|
|
|
/* Note that this relies on all numbers being less than all
|
|
|
|
* letters, so
|
|
|
|
* that de0 < del0.
|
|
|
|
*/
|
|
|
|
res = strncmp(p1, p2, l1);
|
|
|
|
|
|
|
|
/* names are different -> compare them */
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* with identical name part, go to numeric part */
|
|
|
|
p1 += l1;
|
|
|
|
p2 += l1;
|
|
|
|
|
2017-10-05 01:13:56 +02:00
|
|
|
if (!*p1 && !*p2)
|
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!*p1)
|
|
|
|
return -1;
|
|
|
|
if (!*p2)
|
|
|
|
return 1;
|
|
|
|
|
2018-09-17 18:22:59 +02:00
|
|
|
x1 = strtol(p1, (char **)&p1, 10);
|
|
|
|
x2 = strtol(p2, (char **)&p2, 10);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* let's compare numbers now */
|
|
|
|
if (x1 < x2)
|
|
|
|
return -1;
|
|
|
|
if (x1 > x2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* numbers were equal, lets do it again..
|
|
|
|
(it happens with name like "eth123.456:789") */
|
|
|
|
}
|
|
|
|
if (*p1)
|
|
|
|
return 1;
|
|
|
|
if (*p2)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2003-08-01 02:24:13 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 03:06:01 +02:00
|
|
|
static int if_cmp_func(const struct interface *ifp1,
|
|
|
|
const struct interface *ifp2)
|
2016-03-31 18:07:34 +02:00
|
|
|
{
|
2018-09-17 18:22:59 +02:00
|
|
|
return if_cmp_name_func(ifp1->name, ifp2->name);
|
2016-03-31 18:07:34 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 03:06:04 +02:00
|
|
|
static int if_cmp_index_func(const struct interface *ifp1,
|
|
|
|
const struct interface *ifp2)
|
|
|
|
{
|
|
|
|
return ifp1->ifindex - ifp2->ifindex;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Create new interface structure. */
|
2017-10-03 03:05:57 +02:00
|
|
|
struct interface *if_create(const char *name, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_get(vrf_id, NULL);
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
ifp = XCALLOC(MTYPE_IF, sizeof(struct interface));
|
|
|
|
ifp->ifindex = IFINDEX_INTERNAL;
|
|
|
|
|
|
|
|
assert(name);
|
2017-10-03 03:05:57 +02:00
|
|
|
strlcpy(ifp->name, name, sizeof(ifp->name));
|
2017-07-17 14:03:14 +02:00
|
|
|
ifp->vrf_id = vrf_id;
|
2017-10-03 03:06:04 +02:00
|
|
|
IFNAME_RB_INSERT(vrf, ifp);
|
2017-07-17 14:03:14 +02:00
|
|
|
ifp->connected = list_new();
|
|
|
|
ifp->connected->del = (void (*)(void *))connected_free;
|
|
|
|
|
|
|
|
ifp->nbr_connected = list_new();
|
|
|
|
ifp->nbr_connected->del = (void (*)(void *))nbr_connected_free;
|
|
|
|
|
|
|
|
/* Enable Link-detection by default */
|
|
|
|
SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
|
|
|
|
|
|
|
|
QOBJ_REG(ifp, interface);
|
2018-03-06 20:02:52 +01:00
|
|
|
hook_call(if_add, ifp);
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 18:38:33 +01:00
|
|
|
/* Create new interface structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id)
|
2016-02-01 18:38:33 +01:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct vrf *old_vrf, *vrf;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* remove interface from old master vrf list */
|
2018-05-09 06:34:57 +02:00
|
|
|
old_vrf = vrf_lookup_by_id(ifp->vrf_id);
|
|
|
|
if (old_vrf) {
|
|
|
|
IFNAME_RB_REMOVE(old_vrf, ifp);
|
2017-10-03 03:06:04 +02:00
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
2018-05-09 06:34:57 +02:00
|
|
|
IFINDEX_RB_REMOVE(old_vrf, ifp);
|
2017-10-03 03:06:04 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
ifp->vrf_id = vrf_id;
|
2017-10-03 03:06:01 +02:00
|
|
|
vrf = vrf_get(ifp->vrf_id, NULL);
|
2017-10-03 03:06:04 +02:00
|
|
|
|
|
|
|
IFNAME_RB_INSERT(vrf, ifp);
|
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_INSERT(vrf, ifp);
|
2018-05-09 06:34:57 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HACK: Change the interface VRF in the running configuration directly,
|
|
|
|
* bypassing the northbound layer. This is necessary to avoid deleting
|
|
|
|
* the interface and readding it in the new VRF, which would have
|
|
|
|
* several implications.
|
|
|
|
*/
|
|
|
|
if (yang_module_find("frr-interface")) {
|
|
|
|
struct lyd_node *if_dnode;
|
|
|
|
|
2019-04-03 21:31:18 +02:00
|
|
|
pthread_rwlock_wrlock(&running_config->lock);
|
|
|
|
{
|
|
|
|
if_dnode = yang_dnode_get(
|
|
|
|
running_config->dnode,
|
|
|
|
"/frr-interface:lib/interface[name='%s'][vrf='%s']/vrf",
|
|
|
|
ifp->name, old_vrf->name);
|
|
|
|
if (if_dnode) {
|
|
|
|
yang_dnode_change_leaf(if_dnode, vrf->name);
|
|
|
|
running_config->version++;
|
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
}
|
2019-04-03 21:31:18 +02:00
|
|
|
pthread_rwlock_unlock(&running_config->lock);
|
2018-05-09 06:34:57 +02:00
|
|
|
}
|
2016-02-01 18:38:33 +01:00
|
|
|
}
|
|
|
|
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
/* Delete interface structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void if_delete_retain(struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-03-06 20:02:52 +01:00
|
|
|
hook_call(if_del, ifp);
|
2017-07-17 14:03:14 +02:00
|
|
|
QOBJ_UNREG(ifp);
|
2016-09-27 14:51:08 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Free connected address list */
|
|
|
|
list_delete_all_node(ifp->connected);
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Free connected nbr address list */
|
|
|
|
list_delete_all_node(ifp->nbr_connected);
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete and free interface structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void if_delete(struct interface *ifp)
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
{
|
2017-10-21 14:24:21 +02:00
|
|
|
struct vrf *vrf;
|
|
|
|
|
|
|
|
vrf = vrf_lookup_by_id(ifp->vrf_id);
|
|
|
|
assert(vrf);
|
2017-10-03 03:06:01 +02:00
|
|
|
|
2017-10-03 03:06:04 +02:00
|
|
|
IFNAME_RB_REMOVE(vrf, ifp);
|
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_REMOVE(vrf, ifp);
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if_delete_retain(ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-10-02 11:39:51 +02:00
|
|
|
list_delete(&ifp->connected);
|
|
|
|
list_delete(&ifp->nbr_connected);
|
2012-03-21 18:37:03 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if_link_params_free(ifp);
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_TMP, ifp->desc);
|
2018-01-29 21:38:03 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
XFREE(MTYPE_IF, ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface existance check by index. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-21 14:24:21 +02:00
|
|
|
struct vrf *vrf;
|
2017-10-03 03:06:04 +02:00
|
|
|
struct interface if_tmp;
|
2017-10-03 03:06:01 +02:00
|
|
|
|
2017-10-21 14:24:21 +02:00
|
|
|
vrf = vrf_lookup_by_id(vrf_id);
|
|
|
|
if (!vrf)
|
|
|
|
return NULL;
|
|
|
|
|
2017-10-03 03:06:04 +02:00
|
|
|
if_tmp.ifindex = ifindex;
|
|
|
|
return RB_FIND(if_index_head, &vrf->ifaces_by_index, &if_tmp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *ifp;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return ((ifp = if_lookup_by_index(ifindex, vrf_id)) != NULL)
|
|
|
|
? ifp->name
|
|
|
|
: "unknown";
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
ifindex_t ifname2ifindex(const char *name, vrf_id_t vrf_id)
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *ifp;
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
|
|
|
|
? ifp->ifindex
|
|
|
|
: IFINDEX_INTERNAL;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface existance check by interface name. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *if_lookup_by_name(const char *name, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
|
|
|
struct interface if_tmp;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-10-21 14:24:21 +02:00
|
|
|
if (!vrf || !name
|
|
|
|
|| strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ)
|
2017-10-03 03:05:57 +02:00
|
|
|
return NULL;
|
2016-03-23 20:38:30 +01:00
|
|
|
|
2017-10-03 03:06:01 +02:00
|
|
|
strlcpy(if_tmp.name, name, sizeof(if_tmp.name));
|
|
|
|
return RB_FIND(if_name_head, &vrf->ifaces_by_name, &if_tmp);
|
2016-03-23 20:38:30 +01:00
|
|
|
}
|
|
|
|
|
2017-10-03 03:05:57 +02:00
|
|
|
struct interface *if_lookup_by_name_all_vrf(const char *name)
|
2005-04-03 00:50:38 +02:00
|
|
|
{
|
2017-10-03 03:05:57 +02:00
|
|
|
struct vrf *vrf;
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *ifp;
|
2005-04-03 00:50:38 +02:00
|
|
|
|
2017-10-03 03:05:57 +02:00
|
|
|
if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ)
|
2017-07-17 14:03:14 +02:00
|
|
|
return NULL;
|
2005-04-03 00:50:38 +02:00
|
|
|
|
2017-10-03 03:05:57 +02:00
|
|
|
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
|
|
|
|
ifp = if_lookup_by_name(name, vrf->vrf_id);
|
|
|
|
if (ifp)
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp;
|
|
|
|
}
|
2017-10-03 03:05:57 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return NULL;
|
2005-04-03 00:50:38 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Lookup interface by IPv4 address. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *if_lookup_exact_address(void *src, int family,
|
|
|
|
vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
struct listnode *cnode;
|
|
|
|
struct interface *ifp;
|
|
|
|
struct prefix *p;
|
|
|
|
struct connected *c;
|
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
2017-07-17 14:03:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
|
|
|
|
p = c->address;
|
|
|
|
|
|
|
|
if (p && (p->family == family)) {
|
|
|
|
if (family == AF_INET) {
|
|
|
|
if (IPV4_ADDR_SAME(
|
|
|
|
&p->u.prefix4,
|
|
|
|
(struct in_addr *)src))
|
|
|
|
return ifp;
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
if (IPV6_ADDR_SAME(
|
|
|
|
&p->u.prefix6,
|
|
|
|
(struct in6_addr *)src))
|
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
}
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
return NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup interface by IPv4 address. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *if_lookup_address(void *matchaddr, int family,
|
|
|
|
vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
struct prefix addr;
|
|
|
|
int bestlen = 0;
|
|
|
|
struct listnode *cnode;
|
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *c;
|
|
|
|
struct connected *match;
|
|
|
|
|
|
|
|
if (family == AF_INET) {
|
|
|
|
addr.family = AF_INET;
|
|
|
|
addr.u.prefix4 = *((struct in_addr *)matchaddr);
|
|
|
|
addr.prefixlen = IPV4_MAX_BITLEN;
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
addr.family = AF_INET6;
|
|
|
|
addr.u.prefix6 = *((struct in6_addr *)matchaddr);
|
|
|
|
addr.prefixlen = IPV6_MAX_BITLEN;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
match = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
2017-07-17 14:03:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
|
|
|
|
if (c->address && (c->address->family == AF_INET)
|
|
|
|
&& prefix_match(CONNECTED_PREFIX(c), &addr)
|
|
|
|
&& (c->address->prefixlen > bestlen)) {
|
|
|
|
bestlen = c->address->prefixlen;
|
|
|
|
match = c;
|
|
|
|
}
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
return match;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2013-08-24 09:55:50 +02:00
|
|
|
/* Lookup interface by prefix */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *if_lookup_prefix(struct prefix *prefix, vrf_id_t vrf_id)
|
2013-08-24 09:55:50 +02:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
struct listnode *cnode;
|
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *c;
|
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
2017-07-17 14:03:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
|
|
|
|
if (prefix_cmp(c->address, prefix) == 0) {
|
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-08-24 09:55:50 +02:00
|
|
|
}
|
|
|
|
|
2019-01-07 20:02:53 +01:00
|
|
|
size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz,
|
|
|
|
struct interface ***result, vrf_id_t vrf_id)
|
|
|
|
{
|
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
|
|
|
|
|
|
|
struct list *rs = list_new();
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
|
|
|
if (ifp->hw_addr_len == (int)addrsz
|
|
|
|
&& !memcmp(hw_addr, ifp->hw_addr, addrsz))
|
|
|
|
listnode_add(rs, ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rs->count) {
|
|
|
|
*result = XCALLOC(MTYPE_TMP,
|
|
|
|
sizeof(struct interface *) * rs->count);
|
|
|
|
list_to_array(rs, (void **)*result, rs->count);
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = rs->count;
|
|
|
|
|
|
|
|
list_delete(&rs);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Get interface by name if given name interface doesn't exist create
|
|
|
|
one. */
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
switch (vrf_get_backend()) {
|
2019-02-11 13:48:12 +01:00
|
|
|
case VRF_BACKEND_UNKNOWN:
|
2018-05-09 06:34:57 +02:00
|
|
|
case VRF_BACKEND_NETNS:
|
2018-05-29 10:34:38 +02:00
|
|
|
ifp = if_lookup_by_name(name, vrf_id);
|
|
|
|
if (ifp)
|
|
|
|
return ifp;
|
2017-12-19 12:44:44 +01:00
|
|
|
return if_create(name, vrf_id);
|
2018-05-09 06:34:57 +02:00
|
|
|
case VRF_BACKEND_VRF_LITE:
|
|
|
|
ifp = if_lookup_by_name_all_vrf(name);
|
|
|
|
if (ifp) {
|
|
|
|
if (ifp->vrf_id == vrf_id)
|
2018-08-30 16:06:03 +02:00
|
|
|
return ifp;
|
2018-05-09 06:34:57 +02:00
|
|
|
/* If it came from the kernel or by way of zclient,
|
|
|
|
* believe it and update the ifp accordingly.
|
|
|
|
*/
|
|
|
|
if_update_to_new_vrf(ifp, vrf_id);
|
|
|
|
return ifp;
|
2018-05-29 10:34:38 +02:00
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
return if_create(name, vrf_id);
|
2016-02-10 18:53:21 +01:00
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
|
|
|
|
return NULL;
|
2015-05-22 11:39:59 +02:00
|
|
|
}
|
|
|
|
|
2017-10-03 03:06:04 +02:00
|
|
|
void if_set_index(struct interface *ifp, ifindex_t ifindex)
|
|
|
|
{
|
2017-10-21 14:24:21 +02:00
|
|
|
struct vrf *vrf;
|
|
|
|
|
|
|
|
vrf = vrf_lookup_by_id(ifp->vrf_id);
|
|
|
|
assert(vrf);
|
2017-10-03 03:06:04 +02:00
|
|
|
|
|
|
|
if (ifp->ifindex == ifindex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_REMOVE(vrf, ifp)
|
|
|
|
|
|
|
|
ifp->ifindex = ifindex;
|
|
|
|
|
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_INSERT(vrf, ifp)
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Does interface up ? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_up(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp->flags & IFF_UP;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 22:03:13 +01:00
|
|
|
/* Is interface running? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_running(const struct interface *ifp)
|
2002-12-13 22:03:13 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp->flags & IFF_RUNNING;
|
2002-12-13 22:03:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the interface operative, eg. either UP & RUNNING
|
2015-05-20 02:40:44 +02:00
|
|
|
or UP & !ZEBRA_INTERFACE_LINK_DETECTION and
|
|
|
|
if ptm checking is enabled, then ptm check has passed */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_operative(const struct interface *ifp)
|
2002-12-13 22:03:13 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ((ifp->flags & IFF_UP)
|
|
|
|
&& (((ifp->flags & IFF_RUNNING)
|
|
|
|
&& (ifp->ptm_status || !ifp->ptm_enable))
|
|
|
|
|| !CHECK_FLAG(ifp->status,
|
|
|
|
ZEBRA_INTERFACE_LINKDETECTION)));
|
2015-05-20 02:40:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the interface operative, eg. either UP & RUNNING
|
|
|
|
or UP & !ZEBRA_INTERFACE_LINK_DETECTION, without PTM check */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_no_ptm_operative(const struct interface *ifp)
|
2015-05-20 02:40:44 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ((ifp->flags & IFF_UP)
|
|
|
|
&& ((ifp->flags & IFF_RUNNING)
|
|
|
|
|| !CHECK_FLAG(ifp->status,
|
|
|
|
ZEBRA_INTERFACE_LINKDETECTION)));
|
2002-12-13 22:03:13 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Is this loopback interface ? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_loopback(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
/* XXX: Do this better, eg what if IFF_WHATEVER means X on platform M
|
|
|
|
* but Y on platform N?
|
|
|
|
*/
|
|
|
|
return (ifp->flags & (IFF_LOOPBACK | IFF_NOXMIT | IFF_VIRTUAL));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2018-03-06 21:55:59 +01:00
|
|
|
/* Check interface is VRF */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_vrf(const struct interface *ifp)
|
2018-03-06 21:55:59 +01:00
|
|
|
{
|
|
|
|
return CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
|
|
|
|
}
|
|
|
|
|
2019-02-04 20:33:06 +01:00
|
|
|
bool if_is_loopback_or_vrf(const struct interface *ifp)
|
2018-08-21 20:03:00 +02:00
|
|
|
{
|
|
|
|
if (if_is_loopback(ifp) || if_is_vrf(ifp))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Does this interface support broadcast ? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_broadcast(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp->flags & IFF_BROADCAST;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Does this interface support broadcast ? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_pointopoint(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp->flags & IFF_POINTOPOINT;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Does this interface support multicast ? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_multicast(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp->flags & IFF_MULTICAST;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Printout flag information into log */
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *if_flag_dump(unsigned long flag)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int separator = 0;
|
|
|
|
static char logbuf[BUFSIZ];
|
|
|
|
|
|
|
|
#define IFF_OUT_LOG(X, STR) \
|
|
|
|
if (flag & (X)) { \
|
|
|
|
if (separator) \
|
2019-04-07 00:38:54 +02:00
|
|
|
strlcat(logbuf, ",", sizeof(logbuf)); \
|
2017-07-17 14:03:14 +02:00
|
|
|
else \
|
|
|
|
separator = 1; \
|
2019-04-07 00:38:54 +02:00
|
|
|
strlcat(logbuf, STR, sizeof(logbuf)); \
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
strlcpy(logbuf, "<", BUFSIZ);
|
|
|
|
IFF_OUT_LOG(IFF_UP, "UP");
|
|
|
|
IFF_OUT_LOG(IFF_BROADCAST, "BROADCAST");
|
|
|
|
IFF_OUT_LOG(IFF_DEBUG, "DEBUG");
|
|
|
|
IFF_OUT_LOG(IFF_LOOPBACK, "LOOPBACK");
|
|
|
|
IFF_OUT_LOG(IFF_POINTOPOINT, "POINTOPOINT");
|
|
|
|
IFF_OUT_LOG(IFF_NOTRAILERS, "NOTRAILERS");
|
|
|
|
IFF_OUT_LOG(IFF_RUNNING, "RUNNING");
|
|
|
|
IFF_OUT_LOG(IFF_NOARP, "NOARP");
|
|
|
|
IFF_OUT_LOG(IFF_PROMISC, "PROMISC");
|
|
|
|
IFF_OUT_LOG(IFF_ALLMULTI, "ALLMULTI");
|
|
|
|
IFF_OUT_LOG(IFF_OACTIVE, "OACTIVE");
|
|
|
|
IFF_OUT_LOG(IFF_SIMPLEX, "SIMPLEX");
|
|
|
|
IFF_OUT_LOG(IFF_LINK0, "LINK0");
|
|
|
|
IFF_OUT_LOG(IFF_LINK1, "LINK1");
|
|
|
|
IFF_OUT_LOG(IFF_LINK2, "LINK2");
|
|
|
|
IFF_OUT_LOG(IFF_MULTICAST, "MULTICAST");
|
|
|
|
IFF_OUT_LOG(IFF_NOXMIT, "NOXMIT");
|
|
|
|
IFF_OUT_LOG(IFF_NORTEXCH, "NORTEXCH");
|
|
|
|
IFF_OUT_LOG(IFF_VIRTUAL, "VIRTUAL");
|
|
|
|
IFF_OUT_LOG(IFF_IPV4, "IPv4");
|
|
|
|
IFF_OUT_LOG(IFF_IPV6, "IPv6");
|
|
|
|
|
2019-04-07 00:38:54 +02:00
|
|
|
strlcat(logbuf, ">", sizeof(logbuf));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
return logbuf;
|
2006-06-15 14:48:17 +02:00
|
|
|
#undef IFF_OUT_LOG
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For debugging */
|
2017-07-17 14:03:14 +02:00
|
|
|
static void if_dump(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct listnode *node;
|
|
|
|
struct connected *c __attribute__((unused));
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, c))
|
|
|
|
zlog_info(
|
|
|
|
"Interface %s vrf %u index %d metric %d mtu %d "
|
|
|
|
"mtu6 %d %s",
|
|
|
|
ifp->name, ifp->vrf_id, ifp->ifindex, ifp->metric,
|
|
|
|
ifp->mtu, ifp->mtu6, if_flag_dump(ifp->flags));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface printing for all interface. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void if_dump_all(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct vrf *vrf;
|
2017-10-03 03:06:01 +02:00
|
|
|
void *ifp;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-09-15 17:47:35 +02:00
|
|
|
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id)
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
2017-10-03 03:06:01 +02:00
|
|
|
if_dump(ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2006-10-16 01:33:50 +02:00
|
|
|
#ifdef SUNOS_5
|
|
|
|
/* Need to handle upgrade from SUNWzebra to Quagga. SUNWzebra created
|
|
|
|
* a seperate struct interface for each logical interface, so config
|
|
|
|
* file may be full of 'interface fooX:Y'. Solaris however does not
|
|
|
|
* expose logical interfaces via PF_ROUTE, so trying to track logical
|
|
|
|
* interfaces can be fruitless, for that reason Quagga only tracks
|
|
|
|
* the primary IP interface.
|
|
|
|
*
|
|
|
|
* We try accomodate SUNWzebra by:
|
|
|
|
* - looking up the interface name, to see whether it exists, if so
|
|
|
|
* its useable
|
|
|
|
* - for protocol daemons, this could only because zebra told us of
|
|
|
|
* the interface
|
|
|
|
* - for zebra, only because it learnt from kernel
|
|
|
|
* - if not:
|
|
|
|
* - search the name to see if it contains a sub-ipif / logical interface
|
|
|
|
* seperator, the ':' char. If it does:
|
|
|
|
* - text up to that char must be the primary name - get that name.
|
|
|
|
* if not:
|
|
|
|
* - no idea, just get the name in its entirety.
|
|
|
|
*/
|
2018-08-28 10:59:02 +02:00
|
|
|
static struct interface *if_sunwzebra_get(const char *name, vrf_id_t vrf_id)
|
2006-10-16 01:33:50 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct interface *ifp;
|
2017-10-03 03:05:57 +02:00
|
|
|
char *cp;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-10-03 03:05:57 +02:00
|
|
|
if ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
|
2017-07-17 14:03:14 +02:00
|
|
|
return ifp;
|
|
|
|
|
|
|
|
/* hunt the primary interface name... */
|
2017-10-03 03:05:57 +02:00
|
|
|
cp = strchr(name, ':');
|
|
|
|
if (cp)
|
|
|
|
*cp = '\0';
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
return if_get_by_name(name, vrf_id);
|
2006-10-16 01:33:50 +02:00
|
|
|
}
|
|
|
|
#endif /* SUNOS_5 */
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2016-12-05 20:28:24 +01:00
|
|
|
#if 0
|
2002-12-13 21:15:29 +01:00
|
|
|
/* For debug purpose. */
|
|
|
|
DEFUN (show_address,
|
|
|
|
show_address_cmd,
|
2016-09-25 18:49:39 +02:00
|
|
|
"show address [vrf NAME]",
|
2002-12-13 21:15:29 +01:00
|
|
|
SHOW_STR
|
2016-09-22 23:40:28 +02:00
|
|
|
"address\n"
|
|
|
|
VRF_CMD_HELP_STR)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-09-29 21:51:56 +02:00
|
|
|
int idx_vrf = 3;
|
2004-09-23 21:18:23 +02:00
|
|
|
struct listnode *node;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *ifc;
|
|
|
|
struct prefix *p;
|
2015-05-22 11:39:59 +02:00
|
|
|
vrf_id_t vrf_id = VRF_DEFAULT;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2016-09-22 23:40:28 +02:00
|
|
|
if (argc > 2)
|
2016-09-30 02:16:31 +02:00
|
|
|
VRF_GET_ID (vrf_id, argv[idx_vrf]->arg);
|
2015-05-22 11:39:59 +02:00
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
p = ifc->address;
|
|
|
|
|
|
|
|
if (p->family == AF_INET)
|
2017-07-13 19:42:42 +02:00
|
|
|
vty_out (vty, "%s/%d\n", inet_ntoa (p->u.prefix4), p->prefixlen);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-05-22 11:39:59 +02:00
|
|
|
DEFUN (show_address_vrf_all,
|
|
|
|
show_address_vrf_all_cmd,
|
2016-09-25 16:10:48 +02:00
|
|
|
"show address vrf all",
|
2015-05-22 11:39:59 +02:00
|
|
|
SHOW_STR
|
|
|
|
"address\n"
|
|
|
|
VRF_ALL_CMD_HELP_STR)
|
|
|
|
{
|
2016-10-29 18:37:11 +02:00
|
|
|
struct vrf *vrf;
|
2015-05-22 11:39:59 +02:00
|
|
|
struct listnode *node;
|
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *ifc;
|
|
|
|
struct prefix *p;
|
|
|
|
|
2016-10-30 00:44:04 +02:00
|
|
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
|
2015-05-22 11:39:59 +02:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
if (RB_EMPTY (if_name_head, &vrf->ifaces_by_name))
|
2015-05-22 11:39:59 +02:00
|
|
|
continue;
|
|
|
|
|
2017-07-13 19:42:42 +02:00
|
|
|
vty_out (vty, "\nVRF %u\n\n", vrf->vrf_id);
|
2015-05-22 11:39:59 +02:00
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
2015-05-22 11:39:59 +02:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
|
2015-05-22 11:39:59 +02:00
|
|
|
{
|
|
|
|
p = ifc->address;
|
|
|
|
|
|
|
|
if (p->family == AF_INET)
|
2017-07-13 19:42:42 +02:00
|
|
|
vty_out (vty, "%s/%d\n", inet_ntoa (p->u.prefix4), p->prefixlen);
|
2015-05-22 11:39:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2016-12-05 20:28:24 +01:00
|
|
|
#endif
|
2015-05-22 11:39:59 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Allocate connected structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *connected_new(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return XCALLOC(MTYPE_CONNECTED, sizeof(struct connected));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:40:40 +02:00
|
|
|
/* Allocate nbr connected structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct nbr_connected *nbr_connected_new(void)
|
2015-05-20 02:40:40 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return XCALLOC(MTYPE_NBR_CONNECTED, sizeof(struct nbr_connected));
|
2015-05-20 02:40:40 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Free connected structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void connected_free(struct connected *connected)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (connected->address)
|
|
|
|
prefix_free(connected->address);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (connected->destination)
|
|
|
|
prefix_free(connected->destination);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_CONNECTED_LABEL, connected->label);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
XFREE(MTYPE_CONNECTED, connected);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:40:40 +02:00
|
|
|
/* Free nbr connected structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void nbr_connected_free(struct nbr_connected *connected)
|
2015-05-20 02:40:40 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (connected->address)
|
|
|
|
prefix_free(connected->address);
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
XFREE(MTYPE_NBR_CONNECTED, connected);
|
2015-05-20 02:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If same interface nbr address already exists... */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct nbr_connected *nbr_connected_check(struct interface *ifp,
|
|
|
|
struct prefix *p)
|
2015-05-20 02:40:40 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct nbr_connected *ifc;
|
|
|
|
struct listnode *node;
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node, ifc))
|
|
|
|
if (prefix_same(ifc->address, p))
|
|
|
|
return ifc;
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return NULL;
|
2015-05-20 02:40:40 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Print if_addr structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static void __attribute__((unused))
|
|
|
|
connected_log(struct connected *connected, char *str)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct prefix *p;
|
|
|
|
struct interface *ifp;
|
|
|
|
char logbuf[BUFSIZ];
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
ifp = connected->ifp;
|
|
|
|
p = connected->address;
|
|
|
|
|
|
|
|
snprintf(logbuf, BUFSIZ, "%s interface %s vrf %u %s %s/%d ", str,
|
|
|
|
ifp->name, ifp->vrf_id, prefix_family_str(p),
|
|
|
|
inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
|
|
|
|
|
|
|
|
p = connected->destination;
|
|
|
|
if (p) {
|
|
|
|
strncat(logbuf, inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
|
|
|
|
BUFSIZ - strlen(logbuf));
|
|
|
|
}
|
|
|
|
zlog_info("%s", logbuf);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:40:40 +02:00
|
|
|
/* Print if_addr structure. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static void __attribute__((unused))
|
|
|
|
nbr_connected_log(struct nbr_connected *connected, char *str)
|
2015-05-20 02:40:40 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct prefix *p;
|
|
|
|
struct interface *ifp;
|
|
|
|
char logbuf[BUFSIZ];
|
|
|
|
char buf[BUFSIZ];
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
ifp = connected->ifp;
|
|
|
|
p = connected->address;
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
snprintf(logbuf, BUFSIZ, "%s interface %s %s %s/%d ", str, ifp->name,
|
|
|
|
prefix_family_str(p),
|
|
|
|
inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
|
2015-05-20 02:40:40 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_info("%s", logbuf);
|
2015-05-20 02:40:40 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* If two connected address has same prefix return 1. */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int connected_same_prefix(struct prefix *p1, struct prefix *p2)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (p1->family == p2->family) {
|
|
|
|
if (p1->family == AF_INET
|
|
|
|
&& IPV4_ADDR_SAME(&p1->u.prefix4, &p2->u.prefix4))
|
|
|
|
return 1;
|
|
|
|
if (p1->family == AF_INET6
|
|
|
|
&& IPV6_ADDR_SAME(&p1->u.prefix6, &p2->u.prefix6))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *connected_lookup_prefix_exact(struct interface *ifp,
|
|
|
|
struct prefix *p)
|
2016-05-12 01:11:06 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct listnode *node;
|
|
|
|
struct listnode *next;
|
|
|
|
struct connected *ifc;
|
2016-05-12 01:11:06 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
for (node = listhead(ifp->connected); node; node = next) {
|
|
|
|
ifc = listgetdata(node);
|
|
|
|
next = node->next;
|
2016-05-12 01:11:06 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (connected_same_prefix(ifc->address, p))
|
|
|
|
return ifc;
|
|
|
|
}
|
|
|
|
return NULL;
|
2016-05-12 01:11:06 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *connected_delete_by_prefix(struct interface *ifp,
|
|
|
|
struct prefix *p)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct listnode *node;
|
|
|
|
struct listnode *next;
|
|
|
|
struct connected *ifc;
|
|
|
|
|
|
|
|
/* In case of same prefix come, replace it with new one. */
|
|
|
|
for (node = listhead(ifp->connected); node; node = next) {
|
|
|
|
ifc = listgetdata(node);
|
|
|
|
next = node->next;
|
|
|
|
|
|
|
|
if (connected_same_prefix(ifc->address, p)) {
|
|
|
|
listnode_delete(ifp->connected, ifc);
|
|
|
|
return ifc;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
return NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2016-05-12 00:52:30 +02:00
|
|
|
/* Find the address on our side that will be used when packets
|
2002-12-13 21:50:29 +01:00
|
|
|
are sent to dst. */
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *connected_lookup_prefix(struct interface *ifp,
|
|
|
|
struct prefix *addr)
|
2002-12-13 21:50:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct listnode *cnode;
|
|
|
|
struct connected *c;
|
|
|
|
struct connected *match;
|
|
|
|
|
|
|
|
match = NULL;
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
|
|
|
|
if (c->address && (c->address->family == addr->family)
|
|
|
|
&& prefix_match(CONNECTED_PREFIX(c), addr)
|
|
|
|
&& (!match
|
|
|
|
|| (c->address->prefixlen > match->address->prefixlen)))
|
|
|
|
match = c;
|
|
|
|
}
|
|
|
|
return match;
|
2002-12-13 21:50:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *connected_add_by_prefix(struct interface *ifp,
|
|
|
|
struct prefix *p,
|
|
|
|
struct prefix *destination)
|
2004-05-08 07:00:31 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct connected *ifc;
|
2004-05-08 07:00:31 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Allocate new connected address. */
|
|
|
|
ifc = connected_new();
|
|
|
|
ifc->ifp = ifp;
|
2004-05-08 07:00:31 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Fetch interface address */
|
|
|
|
ifc->address = prefix_new();
|
|
|
|
memcpy(ifc->address, p, sizeof(struct prefix));
|
2004-05-08 07:00:31 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Fetch dest address */
|
|
|
|
if (destination) {
|
|
|
|
ifc->destination = prefix_new();
|
|
|
|
memcpy(ifc->destination, destination, sizeof(struct prefix));
|
|
|
|
}
|
2004-05-08 07:00:31 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Add connected address to the interface. */
|
|
|
|
listnode_add(ifp->connected, ifc);
|
|
|
|
return ifc;
|
2004-05-08 07:00:31 +02:00
|
|
|
}
|
|
|
|
|
2019-01-25 22:48:17 +01:00
|
|
|
struct connected *connected_get_linklocal(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct listnode *n;
|
|
|
|
struct connected *c = NULL;
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) {
|
|
|
|
if (c->address->family == AF_INET6
|
|
|
|
&& IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
#if 0 /* this route_table of struct connected's is unused \
|
|
|
|
* however, it would be good to use a route_table rather than \
|
|
|
|
* a list.. \
|
|
|
|
*/
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Interface looking up by interface's address. */
|
|
|
|
/* Interface's IPv4 address reverse lookup table. */
|
|
|
|
struct route_table *ifaddr_ipv4_table;
|
|
|
|
/* struct route_table *ifaddr_ipv6_table; */
|
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct route_node *rn;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
|
|
|
|
p.family = AF_INET;
|
|
|
|
p.prefixlen = IPV4_MAX_PREFIXLEN;
|
|
|
|
p.prefix = *ifaddr;
|
|
|
|
|
|
|
|
rn = route_node_get (ifaddr_ipv4_table, (struct prefix *) &p);
|
|
|
|
if (rn)
|
|
|
|
{
|
|
|
|
route_unlock_node (rn);
|
|
|
|
zlog_info ("ifaddr_ipv4_add(): address %s is already added",
|
|
|
|
inet_ntoa (*ifaddr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rn->info = ifp;
|
|
|
|
}
|
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
static void
|
2002-12-13 21:15:29 +01:00
|
|
|
ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct route_node *rn;
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
|
|
|
|
p.family = AF_INET;
|
|
|
|
p.prefixlen = IPV4_MAX_PREFIXLEN;
|
|
|
|
p.prefix = *ifaddr;
|
|
|
|
|
|
|
|
rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
|
|
|
|
if (! rn)
|
|
|
|
{
|
|
|
|
zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
|
|
|
|
inet_ntoa (*ifaddr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rn->info = NULL;
|
|
|
|
route_unlock_node (rn);
|
|
|
|
route_unlock_node (rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lookup interface by interface's IP address or interface index. */
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
static struct interface *
|
2016-01-18 11:12:10 +01:00
|
|
|
ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
struct route_node *rn;
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
if (addr)
|
|
|
|
{
|
|
|
|
p.family = AF_INET;
|
|
|
|
p.prefixlen = IPV4_MAX_PREFIXLEN;
|
|
|
|
p.prefix = *addr;
|
|
|
|
|
|
|
|
rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
|
|
|
|
if (! rn)
|
|
|
|
return NULL;
|
2018-02-18 01:02:55 +01:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
ifp = rn->info;
|
|
|
|
route_unlock_node (rn);
|
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
else
|
2017-03-10 21:45:28 +01:00
|
|
|
return if_lookup_by_index(ifindex, VRF_DEFAULT);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
#endif /* ifaddr_ipv4_table */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-10-03 03:06:01 +02:00
|
|
|
void if_terminate(struct vrf *vrf)
|
2010-11-10 22:00:54 +01:00
|
|
|
{
|
2017-10-03 03:06:01 +02:00
|
|
|
struct interface *ifp;
|
2010-11-10 22:00:54 +01:00
|
|
|
|
2018-02-18 01:02:55 +01:00
|
|
|
while (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
|
|
|
|
ifp = RB_ROOT(if_name_head, &vrf->ifaces_by_name);
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (ifp->node) {
|
|
|
|
ifp->node->info = NULL;
|
|
|
|
route_unlock_node(ifp->node);
|
|
|
|
}
|
|
|
|
if_delete(ifp);
|
|
|
|
}
|
2010-11-10 22:00:54 +01:00
|
|
|
}
|
2016-01-15 16:36:33 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *if_link_type_str(enum zebra_link_type llt)
|
2016-01-15 16:36:33 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
switch (llt) {
|
2016-01-15 16:36:33 +01:00
|
|
|
#define llts(T,S) case (T): return (S)
|
2017-07-17 14:03:14 +02:00
|
|
|
llts(ZEBRA_LLT_UNKNOWN, "Unknown");
|
|
|
|
llts(ZEBRA_LLT_ETHER, "Ethernet");
|
|
|
|
llts(ZEBRA_LLT_EETHER, "Experimental Ethernet");
|
|
|
|
llts(ZEBRA_LLT_AX25, "AX.25 Level 2");
|
|
|
|
llts(ZEBRA_LLT_PRONET, "PROnet token ring");
|
|
|
|
llts(ZEBRA_LLT_IEEE802, "IEEE 802.2 Ethernet/TR/TB");
|
|
|
|
llts(ZEBRA_LLT_ARCNET, "ARCnet");
|
|
|
|
llts(ZEBRA_LLT_APPLETLK, "AppleTalk");
|
|
|
|
llts(ZEBRA_LLT_DLCI, "Frame Relay DLCI");
|
|
|
|
llts(ZEBRA_LLT_ATM, "ATM");
|
|
|
|
llts(ZEBRA_LLT_METRICOM, "Metricom STRIP");
|
|
|
|
llts(ZEBRA_LLT_IEEE1394, "IEEE 1394 IPv4");
|
|
|
|
llts(ZEBRA_LLT_EUI64, "EUI-64");
|
|
|
|
llts(ZEBRA_LLT_INFINIBAND, "InfiniBand");
|
|
|
|
llts(ZEBRA_LLT_SLIP, "SLIP");
|
|
|
|
llts(ZEBRA_LLT_CSLIP, "Compressed SLIP");
|
|
|
|
llts(ZEBRA_LLT_SLIP6, "SLIPv6");
|
|
|
|
llts(ZEBRA_LLT_CSLIP6, "Compressed SLIPv6");
|
|
|
|
llts(ZEBRA_LLT_ROSE, "ROSE packet radio");
|
|
|
|
llts(ZEBRA_LLT_X25, "CCITT X.25");
|
|
|
|
llts(ZEBRA_LLT_PPP, "PPP");
|
|
|
|
llts(ZEBRA_LLT_CHDLC, "Cisco HDLC");
|
|
|
|
llts(ZEBRA_LLT_RAWHDLC, "Raw HDLC");
|
|
|
|
llts(ZEBRA_LLT_LAPB, "LAPB");
|
|
|
|
llts(ZEBRA_LLT_IPIP, "IPIP Tunnel");
|
|
|
|
llts(ZEBRA_LLT_IPIP6, "IPIP6 Tunnel");
|
|
|
|
llts(ZEBRA_LLT_FRAD, "FRAD");
|
|
|
|
llts(ZEBRA_LLT_SKIP, "SKIP vif");
|
|
|
|
llts(ZEBRA_LLT_LOOPBACK, "Loopback");
|
|
|
|
llts(ZEBRA_LLT_LOCALTLK, "Localtalk");
|
|
|
|
llts(ZEBRA_LLT_FDDI, "FDDI");
|
|
|
|
llts(ZEBRA_LLT_SIT, "IPv6-in-IPv4 SIT");
|
|
|
|
llts(ZEBRA_LLT_IPDDP, "IP-in-DDP tunnel");
|
|
|
|
llts(ZEBRA_LLT_IPGRE, "GRE over IP");
|
|
|
|
llts(ZEBRA_LLT_PIMREG, "PIMSM registration");
|
|
|
|
llts(ZEBRA_LLT_HIPPI, "HiPPI");
|
|
|
|
llts(ZEBRA_LLT_IRDA, "IrDA");
|
|
|
|
llts(ZEBRA_LLT_FCPP, "Fibre-Channel PtP");
|
|
|
|
llts(ZEBRA_LLT_FCAL, "Fibre-Channel Arbitrated Loop");
|
|
|
|
llts(ZEBRA_LLT_FCPL, "Fibre-Channel Public Loop");
|
|
|
|
llts(ZEBRA_LLT_FCFABRIC, "Fibre-Channel Fabric");
|
|
|
|
llts(ZEBRA_LLT_IEEE802_TR, "IEEE 802.2 Token Ring");
|
|
|
|
llts(ZEBRA_LLT_IEEE80211, "IEEE 802.11");
|
|
|
|
llts(ZEBRA_LLT_IEEE80211_RADIOTAP, "IEEE 802.11 Radiotap");
|
|
|
|
llts(ZEBRA_LLT_IEEE802154, "IEEE 802.15.4");
|
|
|
|
llts(ZEBRA_LLT_IEEE802154_PHY, "IEEE 802.15.4 Phy");
|
|
|
|
default:
|
2018-09-13 21:34:28 +02:00
|
|
|
flog_err(EC_LIB_DEVELOPMENT, "Unknown value %d", llt);
|
2017-07-17 14:03:14 +02:00
|
|
|
return "Unknown type!";
|
2016-01-15 16:36:33 +01:00
|
|
|
#undef llts
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
2016-01-15 16:36:33 +01:00
|
|
|
}
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct if_link_params *if_link_params_get(struct interface *ifp)
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int i;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (ifp->link_params != NULL)
|
|
|
|
return ifp->link_params;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct if_link_params *iflp =
|
|
|
|
XCALLOC(MTYPE_IF_LINK_PARAMS, sizeof(struct if_link_params));
|
|
|
|
if (iflp == NULL)
|
|
|
|
return NULL;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set TE metric equal to standard metric */
|
|
|
|
iflp->te_metric = ifp->metric;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Compute default bandwidth based on interface */
|
|
|
|
iflp->default_bw =
|
|
|
|
((ifp->bandwidth ? ifp->bandwidth : DEFAULT_BANDWIDTH)
|
|
|
|
* TE_KILO_BIT / TE_BYTE);
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Set Max, Reservable and Unreserved Bandwidth */
|
|
|
|
iflp->max_bw = iflp->default_bw;
|
|
|
|
iflp->max_rsv_bw = iflp->default_bw;
|
|
|
|
for (i = 0; i < MAX_CLASS_TYPE; i++)
|
|
|
|
iflp->unrsv_bw[i] = iflp->default_bw;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Update Link parameters status */
|
|
|
|
iflp->lp_status =
|
|
|
|
LP_TE_METRIC | LP_MAX_BW | LP_MAX_RSV_BW | LP_UNRSV_BW;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Finally attach newly created Link Parameters */
|
|
|
|
ifp->link_params = iflp;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return iflp;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void if_link_params_free(struct interface *ifp)
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (ifp->link_params == NULL)
|
|
|
|
return;
|
|
|
|
XFREE(MTYPE_IF_LINK_PARAMS, ifp->link_params);
|
|
|
|
ifp->link_params = NULL;
|
Update Traffic Engineering Support for OSPFD
NOTE: I am squashing several commits together because they
do not independently compile and we need this ability to
do any type of sane testing on the patches. Since this
series builds together I am doing this. -DBS
This new structure is the basis to get new link parameters for
Traffic Engineering from Zebra/interface layer to OSPFD and ISISD
for the support of Traffic Engineering
* lib/if.[c,h]: link parameters struture and get/set functions
* lib/command.[c,h]: creation of a new link-node
* lib/zclient.[c,h]: modification to the ZBUS message to convey the
link parameters structure
* lib/zebra.h: New ZBUS message
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support for IEEE 754 format
* lib/stream.[c,h]: Add stream_get{f,d} and stream_put{f,d}) demux and muxers to
safely convert between big-endian IEEE-754 single and double binary
format, as used in IETF RFCs, and C99. Implementation depends on host
using __STDC_IEC_559__, which should be everything we care about. Should
correctly error out otherwise.
* lib/network.[c,h]: Add ntohf and htonf converter
* lib/memtypes.c: Add new memeory type for Traffic Engineering support
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add link parameters support to Zebra
* zebra/interface.c:
- Add new link-params CLI commands
- Add new functions to set/get link parameters for interface
* zebra/redistribute.[c,h]: Add new function to propagate link parameters
to routing daemon (essentially OSPFD and ISISD) for Traffic Engineering.
* zebra/redistribute_null.c: Add new function
zebra_interface_parameters_update()
* zebra/zserv.[c,h]: Add new functions to send link parameters
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Add support of new link-params CLI to vtysh
In vtysh_config.c/vtysh_config_parse_line(), it is not possible to continue
to use the ordered version for adding line i.e. config_add_line_uniq() to print
Interface CLI commands as it completely break the new LINK_PARAMS_NODE.
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
Update Traffic Engineering support for OSPFD
These patches update original code to RFC3630 (OSPF-TE) and add support of
RFC5392 (Inter-AS v2) & RFC7471 (TE metric extensions) and partial support
of RFC6827 (ASON - GMPLS).
* ospfd/ospf_dump.[c,h]: Add new dump functions for Traffic Engineering
* ospfd/ospf_opaque.[c,h]: Add new TLV code points for RFC5392
* ospfd/ospf_packet.c: Update checking of OSPF_OPTION
* ospfd/ospf_vty.[c,h]: Update ospf_str2area_id
* ospfd/ospf_zebra.c: Add new function ospf_interface_link_params() to get
Link Parameters information from the interface to populate Traffic Engineering
metrics
* ospfd/ospfd.[c,h]: Update OSPF_OPTION flags (T -> MT and new DN)
* ospfd/ospf_te.[c,h]: Major modifications to update the code to new
link parameters structure and new RFCs
Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
tmp
2016-04-19 16:21:46 +02:00
|
|
|
}
|
2018-07-08 03:04:33 +02:00
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
/* ----------- CLI commands ----------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface
|
|
|
|
*/
|
|
|
|
DEFPY_NOSH (interface,
|
|
|
|
interface_cmd,
|
|
|
|
"interface IFNAME [vrf NAME$vrfname]",
|
|
|
|
"Select an interface to configure\n"
|
|
|
|
"Interface's name\n"
|
|
|
|
VRF_CMD_HELP_STR)
|
|
|
|
{
|
|
|
|
char xpath_list[XPATH_MAXLEN];
|
|
|
|
vrf_id_t vrf_id;
|
|
|
|
struct interface *ifp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!vrfname)
|
|
|
|
vrfname = VRF_DEFAULT_NAME;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This command requires special handling to maintain backward
|
|
|
|
* compatibility. If a VRF name is not specified, it means we're willing
|
|
|
|
* to accept any interface with the given name on any VRF. If no
|
|
|
|
* interface is found, then a new one should be created on the default
|
|
|
|
* VRF.
|
|
|
|
*/
|
|
|
|
VRF_GET_ID(vrf_id, vrfname, false);
|
|
|
|
ifp = if_lookup_by_name_all_vrf(ifname);
|
|
|
|
if (ifp && ifp->vrf_id != vrf_id) {
|
|
|
|
struct vrf *vrf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case 1: a VRF name was specified, but the found
|
|
|
|
* interface is associated to different VRF. Reject the command.
|
|
|
|
*/
|
|
|
|
if (vrf_id != VRF_DEFAULT) {
|
|
|
|
vty_out(vty, "%% interface %s not in %s vrf\n", ifname,
|
|
|
|
vrfname);
|
|
|
|
return CMD_WARNING_CONFIG_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case 2: a VRF name was *not* specified, and the found
|
|
|
|
* interface is associated to a VRF other than the default one.
|
|
|
|
* Update vrf_id and vrfname to account for that.
|
|
|
|
*/
|
|
|
|
vrf = vrf_lookup_by_id(ifp->vrf_id);
|
|
|
|
assert(vrf);
|
|
|
|
vrf_id = ifp->vrf_id;
|
|
|
|
vrfname = vrf->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(xpath_list, sizeof(xpath_list),
|
|
|
|
"/frr-interface:lib/interface[name='%s'][vrf='%s']", ifname,
|
|
|
|
vrfname);
|
|
|
|
|
lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure
that either all changes made by a command are accepted or none are.
This is done to prevent inconsistent states where only parts of a
command are applied in the event any error happens.
The previous API for converted commands, the nb_cli_cfg_change()
function, required callers to pass an array containing all changes
that needed to be applied in the candidate configuration. The
problem with this API is that it was very inconvenient for complex
commands, which change different configuration options depending
on several factors. This required users to manipulate the array
of configuration changes using low-level primitives, making it
complicated to implement some commands.
To solve this problem, introduce a new API based on the two following
functions:
- nb_cli_enqueue_change()
- nb_cli_apply_changes()
The first function is used to enqueue configuration changes, one
at time. Then the nb_cli_apply_changes() function is used to apply
all the enqueued configuration changes.
To implement this, a static-sized array was allocated in the "vty"
structure, along with a counter of enqueued changes. This eliminates
the need to declare an array of configuration changes in every
converted CLI command, simplifying things quite considerably.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 18:30:14 +01:00
|
|
|
nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
|
|
|
|
ret = nb_cli_apply_changes(vty, xpath_list);
|
2018-05-09 06:34:57 +02:00
|
|
|
if (ret == CMD_SUCCESS) {
|
|
|
|
VTY_PUSH_XPATH(INTERFACE_NODE, xpath_list);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For backward compatibility with old commands we still need
|
|
|
|
* to use the qobj infrastructure. This can be removed once
|
|
|
|
* all interface-level commands are converted to the new
|
|
|
|
* northbound model.
|
|
|
|
*/
|
|
|
|
ifp = if_lookup_by_name(ifname, vrf_id);
|
|
|
|
if (ifp)
|
|
|
|
VTY_PUSH_CONTEXT(INTERFACE_NODE, ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFPY (no_interface,
|
|
|
|
no_interface_cmd,
|
|
|
|
"no interface IFNAME [vrf NAME$vrfname]",
|
|
|
|
NO_STR
|
|
|
|
"Delete a pseudo interface's configuration\n"
|
|
|
|
"Interface's name\n"
|
|
|
|
VRF_CMD_HELP_STR)
|
|
|
|
{
|
|
|
|
if (!vrfname)
|
|
|
|
vrfname = VRF_DEFAULT_NAME;
|
|
|
|
|
2019-01-30 10:54:25 +01:00
|
|
|
nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL);
|
2018-05-09 06:34:57 +02:00
|
|
|
|
lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure
that either all changes made by a command are accepted or none are.
This is done to prevent inconsistent states where only parts of a
command are applied in the event any error happens.
The previous API for converted commands, the nb_cli_cfg_change()
function, required callers to pass an array containing all changes
that needed to be applied in the candidate configuration. The
problem with this API is that it was very inconvenient for complex
commands, which change different configuration options depending
on several factors. This required users to manipulate the array
of configuration changes using low-level primitives, making it
complicated to implement some commands.
To solve this problem, introduce a new API based on the two following
functions:
- nb_cli_enqueue_change()
- nb_cli_apply_changes()
The first function is used to enqueue configuration changes, one
at time. Then the nb_cli_apply_changes() function is used to apply
all the enqueued configuration changes.
To implement this, a static-sized array was allocated in the "vty"
structure, along with a counter of enqueued changes. This eliminates
the need to declare an array of configuration changes in every
converted CLI command, simplifying things quite considerably.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 18:30:14 +01:00
|
|
|
return nb_cli_apply_changes(
|
|
|
|
vty, "/frr-interface:lib/interface[name='%s'][vrf='%s']",
|
|
|
|
ifname, vrfname);
|
2018-05-09 06:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cli_show_interface(struct vty *vty, struct lyd_node *dnode,
|
|
|
|
bool show_defaults)
|
|
|
|
{
|
|
|
|
const char *vrf;
|
|
|
|
|
|
|
|
vrf = yang_dnode_get_string(dnode, "./vrf");
|
|
|
|
|
|
|
|
vty_out(vty, "!\n");
|
|
|
|
vty_out(vty, "interface %s", yang_dnode_get_string(dnode, "./name"));
|
|
|
|
if (!strmatch(vrf, VRF_DEFAULT_NAME))
|
|
|
|
vty_out(vty, " vrf %s", vrf);
|
|
|
|
vty_out(vty, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/description
|
|
|
|
*/
|
|
|
|
DEFPY (interface_desc,
|
|
|
|
interface_desc_cmd,
|
|
|
|
"description LINE...",
|
|
|
|
"Interface specific description\n"
|
|
|
|
"Characters describing this interface\n")
|
|
|
|
{
|
|
|
|
char *desc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
desc = argv_concat(argv, argc, 1);
|
lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure
that either all changes made by a command are accepted or none are.
This is done to prevent inconsistent states where only parts of a
command are applied in the event any error happens.
The previous API for converted commands, the nb_cli_cfg_change()
function, required callers to pass an array containing all changes
that needed to be applied in the candidate configuration. The
problem with this API is that it was very inconvenient for complex
commands, which change different configuration options depending
on several factors. This required users to manipulate the array
of configuration changes using low-level primitives, making it
complicated to implement some commands.
To solve this problem, introduce a new API based on the two following
functions:
- nb_cli_enqueue_change()
- nb_cli_apply_changes()
The first function is used to enqueue configuration changes, one
at time. Then the nb_cli_apply_changes() function is used to apply
all the enqueued configuration changes.
To implement this, a static-sized array was allocated in the "vty"
structure, along with a counter of enqueued changes. This eliminates
the need to declare an array of configuration changes in every
converted CLI command, simplifying things quite considerably.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 18:30:14 +01:00
|
|
|
nb_cli_enqueue_change(vty, "./description", NB_OP_MODIFY, desc);
|
|
|
|
ret = nb_cli_apply_changes(vty, NULL);
|
2018-05-09 06:34:57 +02:00
|
|
|
XFREE(MTYPE_TMP, desc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFPY (no_interface_desc,
|
|
|
|
no_interface_desc_cmd,
|
|
|
|
"no description",
|
|
|
|
NO_STR
|
|
|
|
"Interface specific description\n")
|
|
|
|
{
|
2019-01-30 10:54:25 +01:00
|
|
|
nb_cli_enqueue_change(vty, "./description", NB_OP_DESTROY, NULL);
|
lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure
that either all changes made by a command are accepted or none are.
This is done to prevent inconsistent states where only parts of a
command are applied in the event any error happens.
The previous API for converted commands, the nb_cli_cfg_change()
function, required callers to pass an array containing all changes
that needed to be applied in the candidate configuration. The
problem with this API is that it was very inconvenient for complex
commands, which change different configuration options depending
on several factors. This required users to manipulate the array
of configuration changes using low-level primitives, making it
complicated to implement some commands.
To solve this problem, introduce a new API based on the two following
functions:
- nb_cli_enqueue_change()
- nb_cli_apply_changes()
The first function is used to enqueue configuration changes, one
at time. Then the nb_cli_apply_changes() function is used to apply
all the enqueued configuration changes.
To implement this, a static-sized array was allocated in the "vty"
structure, along with a counter of enqueued changes. This eliminates
the need to declare an array of configuration changes in every
converted CLI command, simplifying things quite considerably.
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 18:30:14 +01:00
|
|
|
|
|
|
|
return nb_cli_apply_changes(vty, NULL);
|
2018-05-09 06:34:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cli_show_interface_desc(struct vty *vty, struct lyd_node *dnode,
|
|
|
|
bool show_defaults)
|
|
|
|
{
|
|
|
|
vty_out(vty, " description %s\n", yang_dnode_get_string(dnode, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface autocomplete. */
|
|
|
|
static void if_autocomplete(vector comps, struct cmd_token *token)
|
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
struct vrf *vrf;
|
|
|
|
|
|
|
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
|
|
|
vector_set(comps, XSTRDUP(MTYPE_COMPLETION, ifp->name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct cmd_variable_handler if_var_handlers[] = {
|
|
|
|
{/* "interface NAME" */
|
|
|
|
.varname = "interface",
|
|
|
|
.completions = if_autocomplete},
|
|
|
|
{.tokenname = "IFNAME", .completions = if_autocomplete},
|
|
|
|
{.tokenname = "INTERFACE", .completions = if_autocomplete},
|
|
|
|
{.completions = NULL}};
|
|
|
|
|
|
|
|
void if_cmd_init(void)
|
|
|
|
{
|
|
|
|
cmd_variable_handler_register(if_var_handlers);
|
|
|
|
|
|
|
|
install_element(CONFIG_NODE, &interface_cmd);
|
|
|
|
install_element(CONFIG_NODE, &no_interface_cmd);
|
|
|
|
|
|
|
|
install_default(INTERFACE_NODE);
|
|
|
|
install_element(INTERFACE_NODE, &interface_desc_cmd);
|
|
|
|
install_element(INTERFACE_NODE, &no_interface_desc_cmd);
|
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
/* ------- Northbound callbacks ------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface
|
|
|
|
*/
|
|
|
|
static int lib_interface_create(enum nb_event event,
|
|
|
|
const struct lyd_node *dnode,
|
|
|
|
union nb_resource *resource)
|
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
const char *ifname;
|
|
|
|
const char *vrfname;
|
|
|
|
struct vrf *vrf;
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
ifname = yang_dnode_get_string(dnode, "./name");
|
|
|
|
vrfname = yang_dnode_get_string(dnode, "./vrf");
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case NB_EV_VALIDATE:
|
|
|
|
vrf = vrf_lookup_by_name(vrfname);
|
|
|
|
if (!vrf) {
|
|
|
|
zlog_warn("%s: VRF %s doesn't exist", __func__,
|
|
|
|
vrfname);
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
if (vrf->vrf_id == VRF_UNKNOWN) {
|
|
|
|
zlog_warn("%s: VRF %s is not active", __func__,
|
|
|
|
vrf->name);
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
2019-02-07 14:55:06 +01:00
|
|
|
|
2019-02-11 13:48:12 +01:00
|
|
|
/* if VRF is netns or not yet known - init for instance
|
|
|
|
* then assumption is that passed config is exact
|
|
|
|
* then the user intent was not to use an other iface
|
|
|
|
*/
|
2018-05-09 06:34:57 +02:00
|
|
|
if (vrf_get_backend() == VRF_BACKEND_VRF_LITE) {
|
|
|
|
ifp = if_lookup_by_name_all_vrf(ifname);
|
|
|
|
if (ifp && ifp->vrf_id != vrf->vrf_id) {
|
|
|
|
zlog_warn(
|
|
|
|
"%s: interface %s already exists in another VRF",
|
|
|
|
__func__, ifp->name);
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NB_EV_PREPARE:
|
|
|
|
case NB_EV_ABORT:
|
|
|
|
break;
|
|
|
|
case NB_EV_APPLY:
|
|
|
|
vrf = vrf_lookup_by_name(vrfname);
|
|
|
|
assert(vrf);
|
|
|
|
#ifdef SUNOS_5
|
|
|
|
ifp = if_sunwzebra_get(ifname, vrf->vrf_id);
|
|
|
|
#else
|
|
|
|
ifp = if_get_by_name(ifname, vrf->vrf_id);
|
|
|
|
#endif /* SUNOS_5 */
|
2019-04-18 16:55:52 +02:00
|
|
|
nb_running_set_entry(dnode, ifp);
|
2018-05-09 06:34:57 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:42:42 +01:00
|
|
|
static int lib_interface_destroy(enum nb_event event,
|
|
|
|
const struct lyd_node *dnode)
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case NB_EV_VALIDATE:
|
2019-04-18 16:55:52 +02:00
|
|
|
ifp = nb_running_get_entry(dnode, NULL, true);
|
2018-05-09 06:34:57 +02:00
|
|
|
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
|
|
|
|
zlog_warn("%s: only inactive interfaces can be deleted",
|
|
|
|
__func__);
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NB_EV_PREPARE:
|
|
|
|
case NB_EV_ABORT:
|
|
|
|
break;
|
|
|
|
case NB_EV_APPLY:
|
2019-04-18 16:55:52 +02:00
|
|
|
ifp = nb_running_unset_entry(dnode);
|
2018-05-09 06:34:57 +02:00
|
|
|
if_delete(ifp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/description
|
|
|
|
*/
|
|
|
|
static int lib_interface_description_modify(enum nb_event event,
|
|
|
|
const struct lyd_node *dnode,
|
|
|
|
union nb_resource *resource)
|
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
const char *description;
|
|
|
|
|
|
|
|
if (event != NB_EV_APPLY)
|
|
|
|
return NB_OK;
|
|
|
|
|
2019-04-18 16:55:52 +02:00
|
|
|
ifp = nb_running_get_entry(dnode, NULL, true);
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_TMP, ifp->desc);
|
2018-05-09 06:34:57 +02:00
|
|
|
description = yang_dnode_get_string(dnode, NULL);
|
|
|
|
ifp->desc = XSTRDUP(MTYPE_TMP, description);
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-02 19:42:42 +01:00
|
|
|
static int lib_interface_description_destroy(enum nb_event event,
|
|
|
|
const struct lyd_node *dnode)
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
if (event != NB_EV_APPLY)
|
|
|
|
return NB_OK;
|
|
|
|
|
2019-04-18 16:55:52 +02:00
|
|
|
ifp = nb_running_get_entry(dnode, NULL, true);
|
2019-02-25 21:18:13 +01:00
|
|
|
XFREE(MTYPE_TMP, ifp->desc);
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clang-format off */
|
|
|
|
const struct frr_yang_module_info frr_interface_info = {
|
|
|
|
.name = "frr-interface",
|
|
|
|
.nodes = {
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface",
|
2019-06-12 19:13:30 +02:00
|
|
|
.cbs = {
|
|
|
|
.create = lib_interface_create,
|
|
|
|
.destroy = lib_interface_destroy,
|
|
|
|
.cli_show = cli_show_interface,
|
|
|
|
},
|
2018-07-08 03:04:33 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/description",
|
2019-06-12 19:13:30 +02:00
|
|
|
.cbs = {
|
|
|
|
.modify = lib_interface_description_modify,
|
|
|
|
.destroy = lib_interface_description_destroy,
|
|
|
|
.cli_show = cli_show_interface_desc,
|
|
|
|
},
|
2018-07-08 03:04:33 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = NULL,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|