2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/*
|
|
|
|
* Interface functions.
|
|
|
|
* Copyright (C) 1997, 98 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
2024-01-10 16:24:01 +01:00
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#ifdef GNU_LINUX
|
|
|
|
#include <linux/if.h>
|
|
|
|
#endif /* GNU_LINUX */
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
#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"
|
2022-11-08 17:59:33 +01:00
|
|
|
#include "admin_group.h"
|
2018-05-09 06:34:57 +02:00
|
|
|
#include "lib/if_clippy.c"
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2019-06-21 08:25:42 +02:00
|
|
|
DEFINE_MTYPE_STATIC(LIB, IF, "Interface");
|
2022-12-02 17:10:24 +01:00
|
|
|
DEFINE_MTYPE_STATIC(LIB, IFDESC, "Intf Desc");
|
2015-05-29 05:48:31 +02:00
|
|
|
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");
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
static void if_set_name(struct interface *ifp, const char *name);
|
2019-08-26 14:38:28 +02:00
|
|
|
static struct interface *if_lookup_by_ifindex(ifindex_t ifindex,
|
|
|
|
vrf_id_t vrf_id);
|
2021-10-14 18:15:14 +02:00
|
|
|
static struct interface *if_lookup_by_index_all_vrf(ifindex_t ifindex);
|
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);
|
|
|
|
|
2023-11-02 21:49:28 +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
|
|
|
|
2023-11-02 21:49:28 +01:00
|
|
|
DEFINE_HOOK(if_real, (struct interface *ifp), (ifp));
|
|
|
|
DEFINE_KOOH(if_unreal, (struct interface *ifp), (ifp));
|
|
|
|
|
|
|
|
DEFINE_HOOK(if_up, (struct interface *ifp), (ifp));
|
|
|
|
DEFINE_KOOH(if_down, (struct interface *ifp), (ifp));
|
2019-09-18 22:20:04 +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
|
|
|
|
*/
|
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
|
|
|
{
|
|
|
|
unsigned int l1, l2;
|
|
|
|
long int x1, x2;
|
|
|
|
int res;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-09-24 01:46:01 +02:00
|
|
|
while (*p1 && *p2) {
|
2022-05-02 15:26:11 +02:00
|
|
|
char *tmp1, *tmp2;
|
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
/* look up to any number */
|
|
|
|
l1 = strcspn(p1, "0123456789");
|
|
|
|
l2 = strcspn(p2, "0123456789");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
/* name lengths are different -> compare names */
|
|
|
|
if (l1 != l2)
|
|
|
|
return (strcmp(p1, p2));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2004-07-17 13:51:29 +02:00
|
|
|
/* Note that this relies on all numbers being less than all
|
|
|
|
* letters, so
|
|
|
|
* that de0 < del0.
|
|
|
|
*/
|
2003-08-01 02:24:13 +02:00
|
|
|
res = strncmp(p1, p2, l1);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
/* names are different -> compare them */
|
|
|
|
if (res)
|
|
|
|
return res;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
/* with identical name part, go to numeric part */
|
|
|
|
p1 += l1;
|
|
|
|
p2 += l1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-10-05 01:13:56 +02:00
|
|
|
if (!*p1 && !*p2)
|
|
|
|
return 0;
|
2004-07-09 14:24:42 +02:00
|
|
|
if (!*p1)
|
|
|
|
return -1;
|
|
|
|
if (!*p2)
|
|
|
|
return 1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-09-29 08:17:56 +02:00
|
|
|
x1 = strtol(p1, &tmp1, 10);
|
|
|
|
x2 = strtol(p2, &tmp2, 10);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
/* let's compare numbers now */
|
|
|
|
if (x1 < x2)
|
|
|
|
return -1;
|
|
|
|
if (x1 > x2)
|
|
|
|
return 1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-02 15:26:11 +02:00
|
|
|
/* Compare string if numbers are equal (distinguish foo-1 from foo-001) */
|
|
|
|
l1 = strspn(p1, "0123456789");
|
|
|
|
l2 = strspn(p2, "0123456789");
|
|
|
|
if (l1 != l2)
|
|
|
|
return (strcmp(p1, p2));
|
|
|
|
|
|
|
|
/* Continue to parse the rest of the string */
|
|
|
|
p1 = (const char *)tmp1;
|
|
|
|
p2 = (const char *)tmp2;
|
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
/* numbers were equal, lets do it again..
|
|
|
|
(it happens with name like "eth123.456:789") */
|
|
|
|
}
|
2003-09-24 01:46:01 +02:00
|
|
|
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)
|
|
|
|
{
|
2020-01-04 01:25:38 +01:00
|
|
|
if (ifp1->ifindex == ifp2->ifindex)
|
|
|
|
return 0;
|
|
|
|
else if (ifp1->ifindex > ifp2->ifindex)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
2017-10-03 03:06:04 +02:00
|
|
|
}
|
|
|
|
|
2019-10-30 01:16:28 +01:00
|
|
|
static void ifp_connected_free(void *arg)
|
|
|
|
{
|
|
|
|
struct connected *c = arg;
|
|
|
|
|
|
|
|
connected_free(&c);
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Create new interface structure. */
|
2021-10-13 14:06:38 +02:00
|
|
|
static struct interface *if_new(struct vrf *vrf)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct interface *ifp;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
assert(vrf);
|
|
|
|
|
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
|
|
|
ifp = XCALLOC(MTYPE_IF, sizeof(struct interface));
|
2019-08-13 18:29:40 +02:00
|
|
|
|
2019-10-10 01:50:13 +02:00
|
|
|
ifp->ifindex = IFINDEX_INTERNAL;
|
|
|
|
ifp->name[0] = '\0';
|
2019-08-13 18:29:40 +02:00
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
ifp->vrf = vrf;
|
2019-08-13 18:29:40 +02:00
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
if_connected_init(ifp->connected);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 02:40:40 +02:00
|
|
|
ifp->nbr_connected = list_new();
|
|
|
|
ifp->nbr_connected->del = (void (*)(void *))nbr_connected_free;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-05-20 01:33:52 +02:00
|
|
|
/* Enable Link-detection by default */
|
|
|
|
SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-09-27 14:51:08 +02:00
|
|
|
QOBJ_REG(ifp, interface);
|
2002-12-13 21:15:29 +01:00
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
|
2019-09-19 04:26:55 +02:00
|
|
|
void if_new_via_zapi(struct interface *ifp)
|
|
|
|
{
|
2023-11-02 21:49:28 +01:00
|
|
|
hook_call(if_real, ifp);
|
2019-09-19 04:26:55 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 15:40:57 +02:00
|
|
|
void if_destroy_via_zapi(struct interface *ifp)
|
|
|
|
{
|
2023-11-02 21:49:28 +01:00
|
|
|
hook_call(if_unreal, ifp);
|
2019-09-19 15:40:57 +02:00
|
|
|
|
2020-08-20 20:42:56 +02:00
|
|
|
ifp->oldifindex = ifp->ifindex;
|
2019-09-19 15:40:57 +02:00
|
|
|
if_set_index(ifp, IFINDEX_INTERNAL);
|
2020-08-20 20:42:56 +02:00
|
|
|
|
2019-09-19 15:59:00 +02:00
|
|
|
if (!ifp->configured)
|
2019-10-30 01:24:10 +01:00
|
|
|
if_delete(&ifp);
|
2019-09-19 15:40:57 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 05:07:44 +02:00
|
|
|
void if_up_via_zapi(struct interface *ifp)
|
|
|
|
{
|
2023-11-02 21:49:28 +01:00
|
|
|
hook_call(if_up, ifp);
|
2019-09-19 05:07:44 +02:00
|
|
|
}
|
|
|
|
|
2019-09-19 05:55:34 +02:00
|
|
|
void if_down_via_zapi(struct interface *ifp)
|
|
|
|
{
|
2023-11-02 21:49:28 +01:00
|
|
|
hook_call(if_down, ifp);
|
2019-09-19 05:55:34 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
static struct interface *if_create_name(const char *name, struct vrf *vrf)
|
2019-08-13 18:29:40 +02:00
|
|
|
{
|
2019-10-10 01:50:13 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
ifp = if_new(vrf);
|
2019-10-10 01:50:13 +02:00
|
|
|
|
|
|
|
if_set_name(ifp, name);
|
|
|
|
|
|
|
|
hook_call(if_add, ifp);
|
|
|
|
return ifp;
|
2019-08-13 18:29:40 +02:00
|
|
|
}
|
|
|
|
|
2019-06-24 01:46:39 +02:00
|
|
|
/* Create new interface structure. */
|
|
|
|
void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id)
|
2016-02-01 18:38:33 +01:00
|
|
|
{
|
2019-06-24 01:46:39 +02:00
|
|
|
struct vrf *old_vrf, *vrf;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-02-01 18:38:33 +01:00
|
|
|
/* remove interface from old master vrf list */
|
2021-10-13 14:06:38 +02:00
|
|
|
old_vrf = ifp->vrf;
|
2019-10-10 01:35:46 +02:00
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
if (ifp->name[0] != '\0')
|
|
|
|
IFNAME_RB_REMOVE(old_vrf, ifp);
|
|
|
|
|
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_REMOVE(old_vrf, ifp);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-10-22 00:17:40 +02:00
|
|
|
vrf = vrf_get(vrf_id, NULL);
|
2021-10-13 14:06:38 +02:00
|
|
|
ifp->vrf = vrf;
|
2017-10-03 03:06:04 +02:00
|
|
|
|
2019-10-10 01:35:46 +02:00
|
|
|
if (ifp->name[0] != '\0')
|
|
|
|
IFNAME_RB_INSERT(vrf, ifp);
|
|
|
|
|
2017-10-03 03:06:04 +02:00
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_INSERT(vrf, ifp);
|
2016-02-01 18:38:33 +01:00
|
|
|
}
|
|
|
|
|
2019-09-17 02:51:11 +02: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. */
|
|
|
|
void if_delete_retain(struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2023-11-22 19:05:41 +01:00
|
|
|
struct connected *ifc;
|
|
|
|
|
2017-08-08 10:50:43 +02:00
|
|
|
hook_call(if_del, ifp);
|
2016-09-27 14:51:08 +02:00
|
|
|
QOBJ_UNREG(ifp);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Free connected address list */
|
2023-11-22 19:05:41 +01:00
|
|
|
while ((ifc = if_connected_pop(ifp->connected)))
|
|
|
|
ifp_connected_free(ifc);
|
2015-05-20 02:40:40 +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. */
|
2019-10-30 01:24:10 +01: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
|
|
|
{
|
2019-10-30 01:24:10 +01:00
|
|
|
struct interface *ptr = *ifp;
|
2021-10-13 14:06:38 +02:00
|
|
|
struct vrf *vrf = ptr->vrf;
|
2017-10-03 03:06:01 +02:00
|
|
|
|
2019-10-30 01:24:10 +01:00
|
|
|
IFNAME_RB_REMOVE(vrf, ptr);
|
|
|
|
if (ptr->ifindex != IFINDEX_INTERNAL)
|
|
|
|
IFINDEX_RB_REMOVE(vrf, ptr);
|
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
|
|
|
|
2019-10-30 01:24:10 +01:00
|
|
|
if_delete_retain(ptr);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
if_connected_fini(ptr->connected);
|
2019-10-30 01:24:10 +01:00
|
|
|
list_delete(&ptr->nbr_connected);
|
2012-03-21 18:37:03 +01:00
|
|
|
|
2019-10-30 01:24:10 +01:00
|
|
|
if_link_params_free(ptr);
|
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
|
|
|
|
2022-12-02 17:10:24 +01:00
|
|
|
XFREE(MTYPE_IFDESC, ptr->desc);
|
2018-01-29 21:38:03 +01:00
|
|
|
|
2019-10-30 01:24:10 +01:00
|
|
|
XFREE(MTYPE_IF, ptr);
|
|
|
|
*ifp = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-08-26 14:38:28 +02:00
|
|
|
/* Used only internally to check within VRF only */
|
|
|
|
static struct interface *if_lookup_by_ifindex(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
|
|
|
}
|
|
|
|
|
2021-10-05 23:33:14 +02:00
|
|
|
/* Interface existence check by index. */
|
2019-08-26 14:38:28 +02:00
|
|
|
struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id)
|
|
|
|
{
|
|
|
|
switch (vrf_get_backend()) {
|
|
|
|
case VRF_BACKEND_UNKNOWN:
|
|
|
|
case VRF_BACKEND_NETNS:
|
|
|
|
return(if_lookup_by_ifindex(ifindex, vrf_id));
|
|
|
|
case VRF_BACKEND_VRF_LITE:
|
|
|
|
return(if_lookup_by_index_all_vrf(ifindex));
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-05 23:33:14 +02:00
|
|
|
/* Interface existence check by index. */
|
2020-10-01 13:06:50 +02:00
|
|
|
struct interface *if_vrf_lookup_by_index_next(ifindex_t ifindex,
|
|
|
|
vrf_id_t vrf_id)
|
|
|
|
{
|
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
|
|
|
struct interface *tmp_ifp;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if (!vrf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (ifindex == 0) {
|
|
|
|
tmp_ifp = RB_MIN(if_index_head, &vrf->ifaces_by_index);
|
|
|
|
/* skip the vrf interface */
|
|
|
|
if (tmp_ifp && if_is_vrf(tmp_ifp))
|
|
|
|
ifindex = tmp_ifp->ifindex;
|
|
|
|
else
|
|
|
|
return tmp_ifp;
|
|
|
|
}
|
|
|
|
|
|
|
|
RB_FOREACH (tmp_ifp, if_index_head, &vrf->ifaces_by_index) {
|
|
|
|
if (found) {
|
|
|
|
/* skip the vrf interface */
|
|
|
|
if (tmp_ifp && if_is_vrf(tmp_ifp))
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
return tmp_ifp;
|
|
|
|
}
|
|
|
|
if (tmp_ifp->ifindex == ifindex)
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-11 13:47:46 +01:00
|
|
|
const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
|
2017-03-10 21:45:28 +01:00
|
|
|
return ((ifp = if_lookup_by_index(ifindex, vrf_id)) != NULL)
|
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
|
|
|
? 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-03-11 13:52:59 +01: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
|
|
|
{
|
|
|
|
struct interface *ifp;
|
|
|
|
|
2019-06-24 01:46:39 +02:00
|
|
|
return ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
|
2017-03-11 13:27:15 +01:00
|
|
|
? ifp->ifindex
|
2009-08-06 13:08:50 +02:00
|
|
|
: IFINDEX_INTERNAL;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2021-10-05 23:33:14 +02:00
|
|
|
/* Interface existence check by interface name. */
|
2019-06-24 01:46:39 +02:00
|
|
|
struct interface *if_lookup_by_name(const char *name, vrf_id_t vrf_id)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-06-24 01:46:39 +02:00
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
2017-10-03 03:06:01 +02:00
|
|
|
struct interface if_tmp;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-11-21 14:08:29 +01:00
|
|
|
if (!vrf || !name || strnlen(name, IFNAMSIZ) == IFNAMSIZ)
|
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
|
|
|
}
|
|
|
|
|
2020-06-21 18:21:51 +02:00
|
|
|
struct interface *if_lookup_by_name_vrf(const char *name, struct vrf *vrf)
|
|
|
|
{
|
|
|
|
struct interface if_tmp;
|
|
|
|
|
2023-11-21 14:08:29 +01:00
|
|
|
if (!name || strnlen(name, IFNAMSIZ) == IFNAMSIZ)
|
2020-06-21 18:21:51 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
strlcpy(if_tmp.name, name, sizeof(if_tmp.name));
|
|
|
|
return RB_FIND(if_name_head, &vrf->ifaces_by_name, &if_tmp);
|
|
|
|
}
|
|
|
|
|
2021-10-14 20:06:38 +02:00
|
|
|
static 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;
|
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
2005-04-07 09:30:20 +02:00
|
|
|
struct interface *ifp;
|
2005-04-03 00:50:38 +02:00
|
|
|
|
2023-11-21 14:08:29 +01:00
|
|
|
if (!name || strnlen(name, IFNAMSIZ) == IFNAMSIZ)
|
2005-04-03 00:50:38 +02:00
|
|
|
return NULL;
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
2021-10-13 22:23:41 +02:00
|
|
|
ifp = if_lookup_by_name_vrf(name, vrf);
|
2017-10-03 03:05:57 +02:00
|
|
|
if (ifp)
|
2005-04-03 00:50:38 +02:00
|
|
|
return ifp;
|
|
|
|
}
|
2017-10-03 03:05:57 +02:00
|
|
|
|
2005-04-03 00:50:38 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-14 18:15:14 +02:00
|
|
|
static struct interface *if_lookup_by_index_all_vrf(ifindex_t ifindex)
|
2019-08-13 18:29:40 +02:00
|
|
|
{
|
|
|
|
struct vrf *vrf;
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
if (ifindex == IFINDEX_INTERNAL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
|
2019-08-26 14:38:28 +02:00
|
|
|
ifp = if_lookup_by_ifindex(ifindex, vrf->vrf_id);
|
2019-08-13 18:29:40 +02:00
|
|
|
if (ifp)
|
|
|
|
return ifp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:35:44 +02:00
|
|
|
/* Lookup interface by IP address.
|
|
|
|
*
|
|
|
|
* supersedes if_lookup_exact_address(), which didn't care about up/down
|
|
|
|
* state. but all users we have either only care if the address is local
|
|
|
|
* (=> use if_address_is_local() please), or care about UP interfaces before
|
|
|
|
* anything else
|
|
|
|
*
|
|
|
|
* to accept only UP interfaces, check if_is_up() on the returned ifp.
|
|
|
|
*/
|
|
|
|
struct interface *if_lookup_address_local(const void *src, int family,
|
2017-03-10 21:51:36 +01:00
|
|
|
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);
|
2021-06-23 16:35:44 +02:00
|
|
|
struct interface *ifp, *best_down = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct prefix *p;
|
|
|
|
struct connected *c;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-06-23 16:35:44 +02:00
|
|
|
if (family != AF_INET && family != AF_INET6)
|
|
|
|
return NULL;
|
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, c) {
|
2002-12-13 21:15:29 +01:00
|
|
|
p = c->address;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-06-23 16:35:44 +02:00
|
|
|
if (!p || p->family != family)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (family == AF_INET) {
|
|
|
|
if (!IPV4_ADDR_SAME(&p->u.prefix4,
|
2015-09-16 08:48:00 +02:00
|
|
|
(struct in_addr *)src))
|
2021-06-23 16:35:44 +02:00
|
|
|
continue;
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
if (!IPV6_ADDR_SAME(&p->u.prefix6,
|
2017-02-02 01:52:54 +01:00
|
|
|
(struct in6_addr *)src))
|
2021-06-23 16:35:44 +02:00
|
|
|
continue;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2021-06-23 16:35:44 +02:00
|
|
|
|
|
|
|
if (if_is_up(ifp))
|
|
|
|
return ifp;
|
|
|
|
if (!best_down)
|
|
|
|
best_down = ifp;
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
2021-06-23 16:35:44 +02:00
|
|
|
return best_down;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2019-08-07 03:16:21 +02:00
|
|
|
/* Lookup interface by IP address. */
|
2019-08-08 01:00:58 +02:00
|
|
|
struct connected *if_lookup_address(const void *matchaddr, int family,
|
2017-03-10 21:54:53 +01:00
|
|
|
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);
|
2002-12-13 21:15:29 +01:00
|
|
|
struct prefix addr;
|
2004-10-19 21:44:43 +02:00
|
|
|
int bestlen = 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *c;
|
2016-11-10 18:35:47 +01:00
|
|
|
struct connected *match;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-09-16 08:48:00 +02:00
|
|
|
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;
|
2022-02-17 20:07:57 +01:00
|
|
|
} else
|
|
|
|
assert(!"Attempted lookup of family not supported");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
match = NULL;
|
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, c) {
|
[PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
whether a peer address has been configured. Comment now shows
the new interpretation of the destination addr: if ZEBRA_IFA_PEER
is set, then it must contain the destination address, otherwise
it may contain the broadcast address or be NULL.
(CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
macros that were specific to IPv4 and not fully general.
(CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
(CONNECTED_PREFIX) New macro giving the prefix to insert into
the RIB: if CONNECTED_PEER, then use the destination (peer) address,
else use the address field.
(CONNECTED_ID) New macro to come up with an identifying address
for the struct connected.
* if.c: (if_lookup_address, connected_lookup_address) Streamline
logic with new CONNECTED_PREFIX macro.
* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
for better performance than the general prefix_copy function.
* zclient.c: (zebra_interface_address_read) For non-null destination
addresses, set prefixlen to equal the address prefixlen. This
is needed to get the new CONNECTED_PREFIX macro to work properly.
* connected.c: (connected_up_ipv4, connected_down_ipv4,
connected_up_ipv6, connected_down_ipv6) Simplify logic using the
new CONNECTED_PREFIX macro.
(connected_add_ipv4) Set prefixlen in destination addresses (required
by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead
of testing for IFF_POINTOPOINT. Delete invalid warning message.
Warn about cases where the ZEBRA_IFA_PEER is set but no
destination address has been supplied (and turn off the flag).
(connected_add_ipv6) Add new flags argument so callers may set
the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies
IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
Set prefixlen in destination address so CONNECTED_PREFIX will work.
* connected.h: (connected_add_ipv6) Add new flags argument so
callers may set the ZEBRA_IFA_PEER flag.
* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
to decide whether the destination address is a peer or broadcast
address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
only when the IFF_POINTOPOINT is set, we now accept a peer
address whenever it is available and not the same as the local
address. Otherwise (no peer address assigned), we check
for a broadcast address (regardless of the IFF_BROADCAST flag).
And must now pass a flags value of ZEBRA_IFA_PEER to
connected_add_ipv4 when a peer address is assigned.
The same new logic is used with the IPv6 code as well (and we
pass the new flags argument to connected_add_ipv6).
(if_get_addr) Do not bother to check IFF_POINTOPOINT: just
issue the SIOCGIFDSTADDR ioctl and see if we get back
a peer address not matching the local address (and set
the ZEBRA_IFA_PEER in that case). If there's no peer address,
try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
without bothering to check the IFF_POINTOPOINT flag. And if
no peer address was found, just try the SIOCGLIFBRDADDR ioctl
without checking the IFF_BROADCAST flag. Call connected_add_ipv4
and connected_add_ipv6 with appropriate flags.
* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
connected_add_ipv6.
* kernel_socket.c: (ifam_read) Must pass new flags argument to
connected_add_ipv6.
* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
to determine local and possible peer address (so there's no longer
a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately.
Pass new flags argument to connected_add_ipv6.
(netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
to determine whether the connected destination address is a
broadcast address.
* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
Simplify logic by using new CONNECTED_PREFIX macro.
* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
macro, both options collapse into the same code.
* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
CONNECTED_ID macro.
(ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
instead of testing the IFF_POINTOPOINT flag.
* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
instead of testing with if_is_pointopoint. And add commented-out
code to implement alternative (in my opinion) more elegant behavior
that has no special-case treatment for PtP addresses.
(ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
macro to simplify logic.
(rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
not give a useful result if prefixlen is 32 (we require a peer
address in such cases).
* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 20:18:21 +01:00
|
|
|
if (c->address && (c->address->family == AF_INET)
|
|
|
|
&& prefix_match(CONNECTED_PREFIX(c), &addr)
|
|
|
|
&& (c->address->prefixlen > bestlen)) {
|
|
|
|
bestlen = c->address->prefixlen;
|
2016-11-10 18:35:47 +01:00
|
|
|
match = c;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2013-08-24 09:55:50 +02:00
|
|
|
/* Lookup interface by prefix */
|
2019-08-08 01:00:58 +02:00
|
|
|
struct interface *if_lookup_prefix(const 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);
|
2013-08-24 09:55:50 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
struct connected *c;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-10-06 20:25:58 +02:00
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, c) {
|
2013-08-24 09:55:50 +02:00
|
|
|
if (prefix_cmp(c->address, prefix) == 0) {
|
|
|
|
return ifp;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2013-08-24 09:55:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:08:08 +02:00
|
|
|
/* Get the VRF loopback interface, i.e. the loopback on the default VRF
|
|
|
|
* or the VRF interface.
|
|
|
|
*/
|
|
|
|
struct interface *if_get_vrf_loopback(vrf_id_t vrf_id)
|
|
|
|
{
|
|
|
|
struct interface *ifp = NULL;
|
|
|
|
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
|
|
|
|
|
|
|
|
FOR_ALL_INTERFACES (vrf, ifp)
|
|
|
|
if (if_is_loopback(ifp))
|
|
|
|
return ifp;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-01-07 20:02:53 +01:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Get interface by name if given name interface doesn't exist create
|
2023-01-11 16:14:11 +01:00
|
|
|
one. */
|
2021-10-13 14:06:38 +02:00
|
|
|
struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id,
|
|
|
|
const char *vrf_name)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2021-10-13 14:06:38 +02:00
|
|
|
struct interface *ifp = NULL;
|
|
|
|
struct vrf *vrf;
|
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:
|
2021-10-13 14:06:38 +02:00
|
|
|
vrf = vrf_get(vrf_id, vrf_name);
|
|
|
|
assert(vrf);
|
|
|
|
|
|
|
|
ifp = if_lookup_by_name_vrf(name, vrf);
|
2018-05-09 06:34:57 +02:00
|
|
|
if (ifp) {
|
|
|
|
/* If it came from the kernel or by way of zclient,
|
|
|
|
* believe it and update the ifp accordingly.
|
|
|
|
*/
|
2021-10-22 00:17:40 +02:00
|
|
|
if (ifp->vrf->vrf_id != vrf_id && vrf_id != VRF_UNKNOWN)
|
2021-10-13 14:06:38 +02:00
|
|
|
if_update_to_new_vrf(ifp, vrf_id);
|
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
return ifp;
|
2018-05-29 10:34:38 +02:00
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
break;
|
2019-08-13 18:29:40 +02:00
|
|
|
case VRF_BACKEND_VRF_LITE:
|
2021-10-13 14:06:38 +02:00
|
|
|
ifp = if_lookup_by_name_all_vrf(name);
|
2019-08-13 18:29:40 +02:00
|
|
|
if (ifp) {
|
|
|
|
/* If it came from the kernel or by way of zclient,
|
|
|
|
* believe it and update the ifp accordingly.
|
|
|
|
*/
|
2021-10-22 00:17:40 +02:00
|
|
|
if (ifp->vrf->vrf_id != vrf_id && vrf_id != VRF_UNKNOWN)
|
2021-10-13 14:06:38 +02:00
|
|
|
if_update_to_new_vrf(ifp, vrf_id);
|
|
|
|
|
2019-08-13 18:29:40 +02:00
|
|
|
return ifp;
|
|
|
|
}
|
2021-10-13 14:06:38 +02:00
|
|
|
|
|
|
|
vrf = vrf_get(vrf_id, vrf_name);
|
|
|
|
assert(vrf);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
2019-08-13 18:29:40 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
return if_create_name(name, vrf);
|
2019-08-13 18:29:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-03 00:50:58 +01:00
|
|
|
int if_set_index(struct interface *ifp, ifindex_t ifindex)
|
2017-10-03 03:06:04 +02:00
|
|
|
{
|
2020-03-03 00:50:58 +01:00
|
|
|
if (ifp->ifindex == ifindex)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is already an interface with this ifindex, we will collide
|
|
|
|
* on insertion, so don't even try.
|
|
|
|
*/
|
2021-10-22 00:17:40 +02:00
|
|
|
if (if_lookup_by_ifindex(ifindex, ifp->vrf->vrf_id))
|
2020-03-03 00:50:58 +01:00
|
|
|
return -1;
|
2017-10-03 03:06:04 +02:00
|
|
|
|
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL)
|
2021-10-13 14:06:38 +02:00
|
|
|
IFINDEX_RB_REMOVE(ifp->vrf, ifp);
|
2017-10-03 03:06:04 +02:00
|
|
|
|
|
|
|
ifp->ifindex = ifindex;
|
|
|
|
|
2020-03-03 00:50:58 +01:00
|
|
|
if (ifp->ifindex != IFINDEX_INTERNAL) {
|
|
|
|
/*
|
|
|
|
* This should never happen, since we checked if there was
|
|
|
|
* already an interface with the desired ifindex at the top of
|
|
|
|
* the function. Nevertheless.
|
|
|
|
*/
|
2021-10-13 14:06:38 +02:00
|
|
|
if (IFINDEX_RB_INSERT(ifp->vrf, ifp))
|
2020-03-03 00:50:58 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-10-03 03:06:04 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
static void if_set_name(struct interface *ifp, const char *name)
|
2019-10-10 01:50:13 +02:00
|
|
|
{
|
|
|
|
if (if_cmp_name_func(ifp->name, name) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ifp->name[0] != '\0')
|
2021-10-13 14:06:38 +02:00
|
|
|
IFNAME_RB_REMOVE(ifp->vrf, ifp);
|
2019-10-10 01:50:13 +02:00
|
|
|
|
|
|
|
strlcpy(ifp->name, name, sizeof(ifp->name));
|
|
|
|
|
|
|
|
if (ifp->name[0] != '\0')
|
2021-10-13 14:06:38 +02:00
|
|
|
IFNAME_RB_INSERT(ifp->vrf, ifp);
|
2019-10-10 01:50:13 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return ifp->flags & IFF_UP;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return ifp->flags & IFF_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
lib: take into account the iff_lower_up flag
In Linux, a network driver can set the interface flags IFF_UP and
IFF_RUNNING although the IFF_LOWER_UP flag is down, which means the
interface is ready but the carrier is down:
> These values contain interface state:
>
> ifinfomsg::if_flags & IFF_UP:
> Interface is admin up
> ifinfomsg::if_flags & IFF_RUNNING:
> Interface is in RFC2863 operational state UP or UNKNOWN. This is for
> backward compatibility, routing daemons, dhcp clients can use this
> flag to determine whether they should use the interface.
> ifinfomsg::if_flags & IFF_LOWER_UP:
> Driver has signaled netif_carrier_on()
However, FRR considers an interface is operational as soon it is up
(IFF_UP) and running (IFF_RUNNING), disregarding the IFF_LOWER_UP flag.
This can lead to a scenario where FRR starts adding routes through an
interface that is technically down at the carrier level, resulting in
kernel errors.
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=243, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (318[if 164]) into the kernel
> Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Carrier for nexthop device is down
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=245, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Nexthop id does not exist
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Invalid argument, type=RTM_NEWROUTE(24), seq=246, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (320[10.125.0.2 if 164]) into the kernel
> Jan 02 18:07:18 dut-vm zebra[283731]: [VYKYC-709DP] default(0:254):0.0.0.0/0: Route install failed
Consider an interface is operational when it has the IFF_UP, IFF_RUNNING
and IFF_LOWER_UP flags.
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/operstates.rst?h=v6.7-rc8#n29
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/nexthop.c?h=v6.7-rc8#n2886
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/netdevice.h?h=v6.7-rc8#n4198
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-10 16:47:03 +01:00
|
|
|
return ((ifp->flags & IFF_UP) &&
|
|
|
|
(((ifp->flags & IFF_RUNNING)
|
|
|
|
#ifdef IFF_LOWER_UP
|
|
|
|
&& (ifp->flags & IFF_LOWER_UP)
|
|
|
|
#endif /* IFF_LOWER_UP */
|
|
|
|
&& (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
|
|
|
{
|
lib: take into account the iff_lower_up flag
In Linux, a network driver can set the interface flags IFF_UP and
IFF_RUNNING although the IFF_LOWER_UP flag is down, which means the
interface is ready but the carrier is down:
> These values contain interface state:
>
> ifinfomsg::if_flags & IFF_UP:
> Interface is admin up
> ifinfomsg::if_flags & IFF_RUNNING:
> Interface is in RFC2863 operational state UP or UNKNOWN. This is for
> backward compatibility, routing daemons, dhcp clients can use this
> flag to determine whether they should use the interface.
> ifinfomsg::if_flags & IFF_LOWER_UP:
> Driver has signaled netif_carrier_on()
However, FRR considers an interface is operational as soon it is up
(IFF_UP) and running (IFF_RUNNING), disregarding the IFF_LOWER_UP flag.
This can lead to a scenario where FRR starts adding routes through an
interface that is technically down at the carrier level, resulting in
kernel errors.
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=243, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (318[if 164]) into the kernel
> Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Carrier for nexthop device is down
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=245, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Nexthop id does not exist
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Invalid argument, type=RTM_NEWROUTE(24), seq=246, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (320[10.125.0.2 if 164]) into the kernel
> Jan 02 18:07:18 dut-vm zebra[283731]: [VYKYC-709DP] default(0:254):0.0.0.0/0: Route install failed
Consider an interface is operational when it has the IFF_UP, IFF_RUNNING
and IFF_LOWER_UP flags.
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/operstates.rst?h=v6.7-rc8#n29
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/nexthop.c?h=v6.7-rc8#n2886
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/netdevice.h?h=v6.7-rc8#n4198
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-10 16:47:03 +01:00
|
|
|
return ((ifp->flags & IFF_UP) &&
|
|
|
|
(((ifp->flags & IFF_RUNNING)
|
|
|
|
#ifdef IFF_LOWER_UP
|
|
|
|
&& (ifp->flags & IFF_LOWER_UP)
|
|
|
|
#endif /* IFF_LOWER_UP */
|
|
|
|
) ||
|
|
|
|
!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 ? */
|
2021-11-16 16:01:03 +01:00
|
|
|
int if_is_loopback_exact(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2004-12-21 23:34:58 +01: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);
|
|
|
|
}
|
|
|
|
|
2021-11-16 16:01:03 +01:00
|
|
|
/* Should this interface be treated as a loopback? */
|
|
|
|
bool if_is_loopback(const struct interface *ifp)
|
2018-08-21 20:03:00 +02:00
|
|
|
{
|
2021-11-16 16:01:03 +01:00
|
|
|
if (if_is_loopback_exact(ifp) || if_is_vrf(ifp))
|
2018-08-21 20:03:00 +02:00
|
|
|
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
|
|
|
{
|
|
|
|
return ifp->flags & IFF_BROADCAST;
|
|
|
|
}
|
|
|
|
|
2022-06-15 07:20:25 +02:00
|
|
|
/* Does this interface support pointopoint ? */
|
2019-02-04 20:33:06 +01:00
|
|
|
int if_is_pointopoint(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
return ifp->flags & IFF_POINTOPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
|
|
|
return ifp->flags & IFF_MULTICAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Printout flag information into log */
|
|
|
|
const char *if_flag_dump(unsigned long flag)
|
|
|
|
{
|
|
|
|
int separator = 0;
|
|
|
|
static char logbuf[BUFSIZ];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
#define IFF_OUT_LOG(X, STR) \
|
2004-12-21 23:34:58 +01:00
|
|
|
if (flag & (X)) { \
|
2002-12-13 21:15:29 +01:00
|
|
|
if (separator) \
|
2019-04-07 00:38:54 +02:00
|
|
|
strlcat(logbuf, ",", sizeof(logbuf)); \
|
2002-12-13 21:15:29 +01:00
|
|
|
else \
|
|
|
|
separator = 1; \
|
2019-04-07 00:38:54 +02:00
|
|
|
strlcat(logbuf, STR, sizeof(logbuf)); \
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2006-06-15 14:48:17 +02:00
|
|
|
strlcpy(logbuf, "<", BUFSIZ);
|
2002-12-13 21:15:29 +01:00
|
|
|
IFF_OUT_LOG(IFF_UP, "UP");
|
lib: take into account the iff_lower_up flag
In Linux, a network driver can set the interface flags IFF_UP and
IFF_RUNNING although the IFF_LOWER_UP flag is down, which means the
interface is ready but the carrier is down:
> These values contain interface state:
>
> ifinfomsg::if_flags & IFF_UP:
> Interface is admin up
> ifinfomsg::if_flags & IFF_RUNNING:
> Interface is in RFC2863 operational state UP or UNKNOWN. This is for
> backward compatibility, routing daemons, dhcp clients can use this
> flag to determine whether they should use the interface.
> ifinfomsg::if_flags & IFF_LOWER_UP:
> Driver has signaled netif_carrier_on()
However, FRR considers an interface is operational as soon it is up
(IFF_UP) and running (IFF_RUNNING), disregarding the IFF_LOWER_UP flag.
This can lead to a scenario where FRR starts adding routes through an
interface that is technically down at the carrier level, resulting in
kernel errors.
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=243, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (318[if 164]) into the kernel
> Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Carrier for nexthop device is down
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Network is down, type=RTM_NEWNEXTHOP(104), seq=245, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [HSYZM-HV7HF] Extended Error: Nexthop id does not exist
> Jan 02 18:07:18 dut-vm zebra[283731]: [WVJCK-PPMGD][EC 4043309093] netlink-dp (NS 0) error: Invalid argument, type=RTM_NEWROUTE(24), seq=246, pid=3112881162
> Jan 02 18:07:18 dut-vm zebra[283731]: [X5XE1-RS0SW][EC 4043309074] Failed to install Nexthop (320[10.125.0.2 if 164]) into the kernel
> Jan 02 18:07:18 dut-vm zebra[283731]: [VYKYC-709DP] default(0:254):0.0.0.0/0: Route install failed
Consider an interface is operational when it has the IFF_UP, IFF_RUNNING
and IFF_LOWER_UP flags.
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/operstates.rst?h=v6.7-rc8#n29
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/nexthop.c?h=v6.7-rc8#n2886
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/netdevice.h?h=v6.7-rc8#n4198
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2024-01-10 16:47:03 +01:00
|
|
|
#ifdef IFF_LOWER_UP
|
|
|
|
IFF_OUT_LOG(IFF_LOWER_UP, "LOWER_UP");
|
|
|
|
#endif /* IFF_LOWER_UP */
|
2002-12-13 21:15:29 +01:00
|
|
|
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");
|
2004-12-21 23:34:58 +01:00
|
|
|
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");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-04-07 00:38:54 +02:00
|
|
|
strlcat(logbuf, ">", sizeof(logbuf));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01: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 */
|
2009-06-12 17:58:49 +02:00
|
|
|
static void if_dump(const struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2023-11-22 19:05:41 +01:00
|
|
|
const struct connected *c;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected_const, ifp->connected, c)
|
2015-05-22 11:39:57 +02:00
|
|
|
zlog_info(
|
2020-03-27 12:35:23 +01:00
|
|
|
"Interface %s vrf %s(%u) index %d metric %d mtu %d mtu6 %d %s",
|
2021-10-22 00:17:40 +02:00
|
|
|
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id,
|
|
|
|
ifp->ifindex, ifp->metric, ifp->mtu, ifp->mtu6,
|
2020-02-14 14:17:40 +01:00
|
|
|
if_flag_dump(ifp->flags));
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Interface printing for all interface. */
|
2009-02-09 19:14:16 +01:00
|
|
|
void if_dump_all(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2016-10-29 18:37:11 +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
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate connected structure. */
|
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
|
|
|
struct connected *connected_new(void)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2008-08-18 23:13:29 +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. */
|
|
|
|
struct nbr_connected *nbr_connected_new(void)
|
|
|
|
{
|
|
|
|
return XCALLOC(MTYPE_NBR_CONNECTED, sizeof(struct nbr_connected));
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Free connected structure. */
|
2019-10-30 01:16:28 +01:00
|
|
|
void connected_free(struct connected **connected)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2019-10-30 01:16:28 +01:00
|
|
|
struct connected *ptr = *connected;
|
|
|
|
|
2020-03-11 17:16:23 +01:00
|
|
|
prefix_free(&ptr->address);
|
|
|
|
prefix_free(&ptr->destination);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-10-30 01:16:28 +01:00
|
|
|
XFREE(MTYPE_CONNECTED_LABEL, ptr->label);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-10-30 01:16:28 +01:00
|
|
|
XFREE(MTYPE_CONNECTED, ptr);
|
|
|
|
*connected = NULL;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 02:40:40 +02:00
|
|
|
/* Free nbr connected structure. */
|
|
|
|
void nbr_connected_free(struct nbr_connected *connected)
|
|
|
|
{
|
|
|
|
if (connected->address)
|
2019-10-30 01:05:27 +01:00
|
|
|
prefix_free(&connected->address);
|
2015-05-20 02:40:40 +02:00
|
|
|
|
|
|
|
XFREE(MTYPE_NBR_CONNECTED, connected);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If same interface nbr address already exists... */
|
|
|
|
struct nbr_connected *nbr_connected_check(struct interface *ifp,
|
|
|
|
struct prefix *p)
|
|
|
|
{
|
|
|
|
struct nbr_connected *ifc;
|
|
|
|
struct listnode *node;
|
|
|
|
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(ifp->nbr_connected, node, ifc))
|
|
|
|
if (prefix_same(ifc->address, p))
|
|
|
|
return ifc;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-10-29 19:02:15 +01:00
|
|
|
/* count the number of connected addresses that are in the given family */
|
|
|
|
unsigned int connected_count_by_family(struct interface *ifp, int family)
|
|
|
|
{
|
|
|
|
struct connected *connected;
|
|
|
|
unsigned int cnt = 0;
|
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, connected)
|
2019-10-29 19:02:15 +01:00
|
|
|
if (connected->address->family == family)
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2016-05-12 01:11:06 +02:00
|
|
|
struct connected *connected_lookup_prefix_exact(struct interface *ifp,
|
2019-08-08 01:00:58 +02:00
|
|
|
const struct prefix *p)
|
2016-05-12 01:11:06 +02:00
|
|
|
{
|
|
|
|
struct connected *ifc;
|
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, ifc) {
|
2024-05-06 17:30:01 +02:00
|
|
|
if (prefix_same(ifc->address, p))
|
2016-05-12 01:11:06 +02:00
|
|
|
return ifc;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
struct connected *connected_delete_by_prefix(struct interface *ifp,
|
|
|
|
struct prefix *p)
|
|
|
|
{
|
|
|
|
struct connected *ifc;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* In case of same prefix come, replace it with new one. */
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each_safe (if_connected, ifp->connected, ifc) {
|
2024-05-06 17:30:01 +02:00
|
|
|
if (prefix_same(ifc->address, p)) {
|
2023-11-22 19:05:41 +01:00
|
|
|
if_connected_del(ifp->connected, ifc);
|
2002-12-13 21:15:29 +01:00
|
|
|
return ifc;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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. */
|
2016-05-12 00:52:30 +02:00
|
|
|
struct connected *connected_lookup_prefix(struct interface *ifp,
|
2019-08-08 01:00:58 +02:00
|
|
|
const struct prefix *addr)
|
2002-12-13 21:50:29 +01:00
|
|
|
{
|
|
|
|
struct connected *c;
|
|
|
|
struct connected *match;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:50:29 +01:00
|
|
|
match = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, c) {
|
2016-05-12 00:52:30 +02:00
|
|
|
if (c->address && (c->address->family == addr->family)
|
|
|
|
&& prefix_match(CONNECTED_PREFIX(c), addr)
|
[PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
whether a peer address has been configured. Comment now shows
the new interpretation of the destination addr: if ZEBRA_IFA_PEER
is set, then it must contain the destination address, otherwise
it may contain the broadcast address or be NULL.
(CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
macros that were specific to IPv4 and not fully general.
(CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
(CONNECTED_PREFIX) New macro giving the prefix to insert into
the RIB: if CONNECTED_PEER, then use the destination (peer) address,
else use the address field.
(CONNECTED_ID) New macro to come up with an identifying address
for the struct connected.
* if.c: (if_lookup_address, connected_lookup_address) Streamline
logic with new CONNECTED_PREFIX macro.
* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
for better performance than the general prefix_copy function.
* zclient.c: (zebra_interface_address_read) For non-null destination
addresses, set prefixlen to equal the address prefixlen. This
is needed to get the new CONNECTED_PREFIX macro to work properly.
* connected.c: (connected_up_ipv4, connected_down_ipv4,
connected_up_ipv6, connected_down_ipv6) Simplify logic using the
new CONNECTED_PREFIX macro.
(connected_add_ipv4) Set prefixlen in destination addresses (required
by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead
of testing for IFF_POINTOPOINT. Delete invalid warning message.
Warn about cases where the ZEBRA_IFA_PEER is set but no
destination address has been supplied (and turn off the flag).
(connected_add_ipv6) Add new flags argument so callers may set
the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies
IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
Set prefixlen in destination address so CONNECTED_PREFIX will work.
* connected.h: (connected_add_ipv6) Add new flags argument so
callers may set the ZEBRA_IFA_PEER flag.
* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
to decide whether the destination address is a peer or broadcast
address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
only when the IFF_POINTOPOINT is set, we now accept a peer
address whenever it is available and not the same as the local
address. Otherwise (no peer address assigned), we check
for a broadcast address (regardless of the IFF_BROADCAST flag).
And must now pass a flags value of ZEBRA_IFA_PEER to
connected_add_ipv4 when a peer address is assigned.
The same new logic is used with the IPv6 code as well (and we
pass the new flags argument to connected_add_ipv6).
(if_get_addr) Do not bother to check IFF_POINTOPOINT: just
issue the SIOCGIFDSTADDR ioctl and see if we get back
a peer address not matching the local address (and set
the ZEBRA_IFA_PEER in that case). If there's no peer address,
try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
without bothering to check the IFF_POINTOPOINT flag. And if
no peer address was found, just try the SIOCGLIFBRDADDR ioctl
without checking the IFF_BROADCAST flag. Call connected_add_ipv4
and connected_add_ipv6 with appropriate flags.
* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
connected_add_ipv6.
* kernel_socket.c: (ifam_read) Must pass new flags argument to
connected_add_ipv6.
* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
to determine local and possible peer address (so there's no longer
a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately.
Pass new flags argument to connected_add_ipv6.
(netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
to determine whether the connected destination address is a
broadcast address.
* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
Simplify logic by using new CONNECTED_PREFIX macro.
* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
macro, both options collapse into the same code.
* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
CONNECTED_ID macro.
(ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
macro.
* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
instead of testing the IFF_POINTOPOINT flag.
* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
instead of testing with if_is_pointopoint. And add commented-out
code to implement alternative (in my opinion) more elegant behavior
that has no special-case treatment for PtP addresses.
(ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
macro to simplify logic.
(rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
not give a useful result if prefixlen is 32 (we require a peer
address in such cases).
* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 20:18:21 +01:00
|
|
|
&& (!match
|
|
|
|
|| (c->address->prefixlen > match->address->prefixlen)))
|
|
|
|
match = c;
|
2002-12-13 21:50:29 +01:00
|
|
|
}
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2004-05-08 07:00:31 +02:00
|
|
|
struct connected *connected_add_by_prefix(struct interface *ifp,
|
|
|
|
struct prefix *p,
|
|
|
|
struct prefix *destination)
|
|
|
|
{
|
|
|
|
struct connected *ifc;
|
|
|
|
|
|
|
|
/* Allocate new connected address. */
|
|
|
|
ifc = connected_new();
|
|
|
|
ifc->ifp = ifp;
|
|
|
|
|
|
|
|
/* Fetch interface address */
|
|
|
|
ifc->address = prefix_new();
|
|
|
|
memcpy(ifc->address, p, sizeof(struct prefix));
|
|
|
|
|
|
|
|
/* Fetch dest address */
|
2004-10-19 21:44:43 +02:00
|
|
|
if (destination) {
|
|
|
|
ifc->destination = prefix_new();
|
|
|
|
memcpy(ifc->destination, destination, sizeof(struct prefix));
|
|
|
|
}
|
2004-05-08 07:00:31 +02:00
|
|
|
|
|
|
|
/* Add connected address to the interface. */
|
2023-11-22 19:05:41 +01:00
|
|
|
if_connected_add_tail(ifp->connected, ifc);
|
2004-05-08 07:00:31 +02:00
|
|
|
return ifc;
|
|
|
|
}
|
|
|
|
|
2019-01-25 22:48:17 +01:00
|
|
|
struct connected *connected_get_linklocal(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct connected *c = NULL;
|
|
|
|
|
2023-11-22 19:05:41 +01:00
|
|
|
frr_each (if_connected, ifp->connected, c) {
|
2019-01-25 22:48:17 +01:00
|
|
|
if (c->address->family == AF_INET6
|
|
|
|
&& IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
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);
|
2021-10-13 14:06:38 +02:00
|
|
|
if_delete(&ifp);
|
2010-11-10 22:00:54 +01:00
|
|
|
}
|
|
|
|
}
|
2016-01-15 16:36:33 +01:00
|
|
|
|
|
|
|
const char *if_link_type_str(enum zebra_link_type llt)
|
|
|
|
{
|
|
|
|
switch (llt) {
|
|
|
|
#define llts(T,S) case (T): return (S)
|
|
|
|
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");
|
2021-10-13 13:58:37 +02:00
|
|
|
llts(ZEBRA_LLT_RSRVD, "Reserved");
|
|
|
|
llts(ZEBRA_LLT_ADAPT, "Adapt");
|
2016-01-15 16:36:33 +01:00
|
|
|
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");
|
2021-10-13 13:58:37 +02:00
|
|
|
llts(ZEBRA_LLT_IP6GRE, "GRE over IPv6");
|
2016-01-15 16:36:33 +01:00
|
|
|
llts(ZEBRA_LLT_PIMREG, "PIMSM registration");
|
|
|
|
llts(ZEBRA_LLT_HIPPI, "HiPPI");
|
2021-10-13 13:58:37 +02:00
|
|
|
llts(ZEBRA_LLT_ECONET, "Acorn Econet");
|
2016-01-15 16:36:33 +01:00
|
|
|
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");
|
|
|
|
#undef llts
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2022-11-08 17:59:33 +01:00
|
|
|
bool if_link_params_cmp(struct if_link_params *iflp1,
|
|
|
|
struct if_link_params *iflp2)
|
|
|
|
{
|
|
|
|
struct if_link_params iflp1_copy, iflp2_copy;
|
|
|
|
|
|
|
|
/* Extended admin-groups in if_link_params contain pointers.
|
|
|
|
* They cannot be compared with memcpy.
|
|
|
|
* Make copies of if_link_params without ext. admin-groups
|
|
|
|
* and compare separately the ext. admin-groups.
|
|
|
|
*/
|
|
|
|
memcpy(&iflp1_copy, iflp1, sizeof(struct if_link_params));
|
|
|
|
memset(&iflp1_copy.ext_admin_grp, 0, sizeof(struct admin_group));
|
|
|
|
|
|
|
|
memcpy(&iflp2_copy, iflp2, sizeof(struct if_link_params));
|
|
|
|
memset(&iflp2_copy.ext_admin_grp, 0, sizeof(struct admin_group));
|
|
|
|
|
|
|
|
if (memcmp(&iflp1_copy, &iflp2_copy, sizeof(struct if_link_params)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!admin_group_cmp(&iflp1->ext_admin_grp, &iflp2->ext_admin_grp))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void if_link_params_copy(struct if_link_params *dst, struct if_link_params *src)
|
|
|
|
{
|
|
|
|
struct admin_group dst_ag;
|
|
|
|
|
|
|
|
/* backup the admin_group structure that contains a pointer */
|
|
|
|
memcpy(&dst_ag, &dst->ext_admin_grp, sizeof(struct admin_group));
|
|
|
|
/* copy the if_link_params structure */
|
|
|
|
memcpy(dst, src, sizeof(struct if_link_params));
|
|
|
|
/* restore the admin_group structure */
|
|
|
|
memcpy(&dst->ext_admin_grp, &dst_ag, sizeof(struct admin_group));
|
|
|
|
/* copy src->ext_admin_grp data to dst->ext_admin_grp data memory */
|
|
|
|
admin_group_copy(&dst->ext_admin_grp, &src->ext_admin_grp);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
struct if_link_params *if_link_params_get(struct interface *ifp)
|
|
|
|
{
|
2022-10-14 17:57:17 +02:00
|
|
|
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
|
|
|
|
2022-10-14 17:57:17 +02:00
|
|
|
struct if_link_params *if_link_params_enable(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct if_link_params *iflp;
|
|
|
|
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
|
|
|
|
2022-10-14 17:57:17 +02:00
|
|
|
iflp = if_link_params_init(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
|
|
|
|
|
|
|
/* Compute default bandwidth based on interface */
|
2016-12-01 16:49:22 +01:00
|
|
|
iflp->default_bw =
|
|
|
|
((ifp->bandwidth ? ifp->bandwidth : DEFAULT_BANDWIDTH)
|
2020-05-19 15:53:02 +02:00
|
|
|
* TE_MEGA_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
|
|
|
|
|
|
|
/* Set Max, Reservable and Unreserved Bandwidth */
|
2016-12-01 16:49:22 +01:00
|
|
|
iflp->max_bw = iflp->default_bw;
|
|
|
|
iflp->max_rsv_bw = 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
|
|
|
for (i = 0; i < MAX_CLASS_TYPE; i++)
|
2016-12-01 16:49:22 +01:00
|
|
|
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
|
|
|
|
|
|
|
/* Update Link parameters status */
|
2024-01-19 17:49:52 +01:00
|
|
|
iflp->lp_status = LP_MAX_BW | LP_MAX_RSV_BW | LP_UNRSV_BW;
|
2022-01-24 17:09:29 +01:00
|
|
|
|
|
|
|
/* Set TE metric equal to standard metric only if it is set */
|
|
|
|
if (ifp->metric != 0) {
|
|
|
|
iflp->te_metric = ifp->metric;
|
|
|
|
iflp->lp_status |= LP_TE_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
|
|
|
|
|
|
|
/* Finally attach newly created Link Parameters */
|
|
|
|
ifp->link_params = iflp;
|
|
|
|
|
|
|
|
return iflp;
|
|
|
|
}
|
|
|
|
|
2022-10-14 17:57:17 +02:00
|
|
|
struct if_link_params *if_link_params_init(struct interface *ifp)
|
|
|
|
{
|
|
|
|
struct if_link_params *iflp = if_link_params_get(ifp);
|
|
|
|
|
|
|
|
if (iflp)
|
|
|
|
return iflp;
|
|
|
|
|
|
|
|
iflp = XCALLOC(MTYPE_IF_LINK_PARAMS, sizeof(struct if_link_params));
|
|
|
|
|
2022-11-08 17:59:33 +01:00
|
|
|
admin_group_init(&iflp->ext_admin_grp);
|
|
|
|
|
2022-10-14 17:57:17 +02:00
|
|
|
ifp->link_params = iflp;
|
|
|
|
|
|
|
|
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
|
|
|
void if_link_params_free(struct interface *ifp)
|
|
|
|
{
|
2022-11-08 17:59:33 +01:00
|
|
|
if (!ifp->link_params)
|
|
|
|
return;
|
|
|
|
|
|
|
|
admin_group_term(&ifp->link_params->ext_admin_grp);
|
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
|
|
|
XFREE(MTYPE_IF_LINK_PARAMS, ifp->link_params);
|
|
|
|
}
|
2018-07-08 03:04:33 +02:00
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
/* ----------- CLI commands ----------- */
|
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
/* Guess the VRF of an interface. */
|
|
|
|
static int vrfname_by_ifname(const char *ifname, const char **vrfname)
|
|
|
|
{
|
|
|
|
struct vrf *vrf;
|
|
|
|
struct interface *ifp;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
|
|
|
|
FOR_ALL_INTERFACES (vrf, ifp) {
|
|
|
|
if (strmatch(ifp->name, ifname)) {
|
|
|
|
*vrfname = vrf->name;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface
|
|
|
|
*/
|
2020-07-06 17:47:44 +02:00
|
|
|
DEFPY_YANG_NOSH (interface,
|
2018-05-09 06:34:57 +02:00
|
|
|
interface_cmd,
|
2019-09-24 18:51:46 +02:00
|
|
|
"interface IFNAME [vrf NAME$vrf_name]",
|
2018-05-09 06:34:57 +02:00
|
|
|
"Select an interface to configure\n"
|
|
|
|
"Interface's name\n"
|
|
|
|
VRF_CMD_HELP_STR)
|
|
|
|
{
|
|
|
|
char xpath_list[XPATH_MAXLEN];
|
2019-06-24 01:46:39 +02:00
|
|
|
struct interface *ifp;
|
2021-10-13 14:06:38 +02:00
|
|
|
struct vrf *vrf;
|
|
|
|
int ret, count;
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2021-10-13 14:06:38 +02:00
|
|
|
if (vrf_is_backend_netns()) {
|
2018-05-09 06:34:57 +02:00
|
|
|
/*
|
2021-10-13 14:06:38 +02:00
|
|
|
* For backward compatibility, if the VRF name is not specified
|
|
|
|
* and there is exactly one interface with this name in the
|
|
|
|
* system, use its VRF. Otherwise fallback to the default VRF.
|
2018-05-09 06:34:57 +02:00
|
|
|
*/
|
2021-10-13 14:06:38 +02:00
|
|
|
if (!vrf_name) {
|
|
|
|
count = vrfname_by_ifname(ifname, &vrf_name);
|
|
|
|
if (count != 1)
|
|
|
|
vrf_name = VRF_DEFAULT_NAME;
|
2018-05-09 06:34:57 +02:00
|
|
|
}
|
2021-11-08 11:33:03 +01:00
|
|
|
|
|
|
|
snprintf(xpath_list, XPATH_MAXLEN,
|
|
|
|
"/frr-interface:lib/interface[name='%s:%s']", vrf_name,
|
|
|
|
ifname);
|
2021-10-13 14:06:38 +02:00
|
|
|
} else {
|
2021-11-08 11:33:03 +01:00
|
|
|
snprintf(xpath_list, XPATH_MAXLEN,
|
|
|
|
"/frr-interface:lib/interface[name='%s']", ifname);
|
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
|
|
|
nb_cli_enqueue_change(vty, ".", NB_OP_CREATE, NULL);
|
2023-01-26 14:56:04 +01:00
|
|
|
ret = nb_cli_apply_changes_clear_pending(vty, "%s", 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.
|
|
|
|
*/
|
2021-10-13 14:06:38 +02:00
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
vrf = vrf_lookup_by_name(vrf_name);
|
|
|
|
if (vrf)
|
|
|
|
ifp = if_lookup_by_name_vrf(ifname, vrf);
|
|
|
|
else
|
|
|
|
ifp = NULL;
|
|
|
|
} else {
|
|
|
|
ifp = if_lookup_by_name_all_vrf(ifname);
|
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
if (ifp)
|
|
|
|
VTY_PUSH_CONTEXT(INTERFACE_NODE, ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-06 17:47:44 +02:00
|
|
|
DEFPY_YANG (no_interface,
|
2018-05-09 06:34:57 +02:00
|
|
|
no_interface_cmd,
|
2019-09-24 18:51:46 +02:00
|
|
|
"no interface IFNAME [vrf NAME$vrf_name]",
|
2018-05-09 06:34:57 +02:00
|
|
|
NO_STR
|
|
|
|
"Delete a pseudo interface's configuration\n"
|
|
|
|
"Interface's name\n"
|
|
|
|
VRF_CMD_HELP_STR)
|
|
|
|
{
|
2021-11-08 11:33:03 +01:00
|
|
|
char xpath_list[XPATH_MAXLEN];
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
/*
|
|
|
|
* For backward compatibility, if the VRF name is not specified
|
|
|
|
* and there is exactly one interface with this name in the
|
|
|
|
* system, use its VRF. Otherwise fallback to the default VRF.
|
|
|
|
*/
|
|
|
|
if (!vrf_name) {
|
|
|
|
count = vrfname_by_ifname(ifname, &vrf_name);
|
|
|
|
if (count != 1)
|
|
|
|
vrf_name = VRF_DEFAULT_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(xpath_list, XPATH_MAXLEN,
|
|
|
|
"/frr-interface:lib/interface[name='%s:%s']", vrf_name,
|
|
|
|
ifname);
|
|
|
|
} else {
|
|
|
|
snprintf(xpath_list, XPATH_MAXLEN,
|
|
|
|
"/frr-interface:lib/interface[name='%s']", ifname);
|
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
|
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
|
|
|
|
2023-01-26 14:56:04 +01:00
|
|
|
return nb_cli_apply_changes(vty, "%s", xpath_list);
|
2021-11-08 11:33:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void netns_ifname_split(const char *xpath, char *ifname, char *vrfname)
|
|
|
|
{
|
|
|
|
char *delim;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
assert(vrf_is_backend_netns());
|
|
|
|
|
|
|
|
delim = strchr(xpath, ':');
|
|
|
|
assert(delim);
|
|
|
|
|
|
|
|
len = delim - xpath;
|
|
|
|
memcpy(vrfname, xpath, len);
|
|
|
|
vrfname[len] = 0;
|
|
|
|
|
|
|
|
strlcpy(ifname, delim + 1, XPATH_MAXLEN);
|
2018-05-09 06:34:57 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 19:08:37 +02:00
|
|
|
static void cli_show_interface(struct vty *vty, const struct lyd_node *dnode,
|
|
|
|
bool show_defaults)
|
2018-05-09 06:34:57 +02:00
|
|
|
{
|
2021-11-08 11:33:03 +01:00
|
|
|
vty_out(vty, "!\n");
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2021-11-08 11:33:03 +01:00
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
char ifname[XPATH_MAXLEN];
|
|
|
|
char vrfname[XPATH_MAXLEN];
|
|
|
|
|
2023-11-29 20:37:23 +01:00
|
|
|
netns_ifname_split(yang_dnode_get_string(dnode, "name"),
|
2021-11-08 11:33:03 +01:00
|
|
|
ifname, vrfname);
|
|
|
|
|
|
|
|
vty_out(vty, "interface %s", ifname);
|
|
|
|
if (!strmatch(vrfname, VRF_DEFAULT_NAME))
|
|
|
|
vty_out(vty, " vrf %s", vrfname);
|
|
|
|
} else {
|
2023-11-29 20:37:23 +01:00
|
|
|
const char *ifname = yang_dnode_get_string(dnode, "name");
|
2021-11-08 11:33:03 +01:00
|
|
|
|
|
|
|
vty_out(vty, "interface %s", ifname);
|
|
|
|
}
|
2018-05-09 06:34:57 +02:00
|
|
|
|
|
|
|
vty_out(vty, "\n");
|
|
|
|
}
|
|
|
|
|
2021-10-13 19:08:37 +02:00
|
|
|
static void cli_show_interface_end(struct vty *vty,
|
|
|
|
const struct lyd_node *dnode)
|
2021-08-08 21:38:50 +02:00
|
|
|
{
|
|
|
|
vty_out(vty, "exit\n");
|
|
|
|
}
|
|
|
|
|
2024-03-06 20:41:35 +01:00
|
|
|
static int cli_cmp_interface(const struct lyd_node *dnode1,
|
|
|
|
const struct lyd_node *dnode2)
|
|
|
|
{
|
|
|
|
const char *ifname1 = yang_dnode_get_string(dnode1, "name");
|
|
|
|
const char *ifname2 = yang_dnode_get_string(dnode2, "name");
|
|
|
|
|
|
|
|
return if_cmp_name_func(ifname1, ifname2);
|
|
|
|
}
|
|
|
|
|
2022-01-23 22:07:20 +01:00
|
|
|
void if_vty_config_start(struct vty *vty, struct interface *ifp)
|
|
|
|
{
|
|
|
|
vty_frame(vty, "!\n");
|
|
|
|
vty_frame(vty, "interface %s", ifp->name);
|
|
|
|
|
|
|
|
if (vrf_is_backend_netns() && strcmp(ifp->vrf->name, VRF_DEFAULT_NAME))
|
|
|
|
vty_frame(vty, " vrf %s", ifp->vrf->name);
|
|
|
|
|
|
|
|
vty_frame(vty, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void if_vty_config_end(struct vty *vty)
|
|
|
|
{
|
|
|
|
vty_endframe(vty, "exit\n!\n");
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/description
|
|
|
|
*/
|
2020-07-06 17:47:44 +02:00
|
|
|
DEFPY_YANG (interface_desc,
|
2018-05-09 06:34:57 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-07-06 17:47:44 +02:00
|
|
|
DEFPY_YANG (no_interface_desc,
|
2018-05-09 06:34:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-13 19:08:37 +02:00
|
|
|
static void cli_show_interface_desc(struct vty *vty,
|
|
|
|
const struct lyd_node *dnode,
|
|
|
|
bool show_defaults)
|
2018-05-09 06:34:57 +02:00
|
|
|
{
|
|
|
|
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}};
|
|
|
|
|
2021-07-29 20:34:56 +02:00
|
|
|
static struct cmd_node interface_node = {
|
|
|
|
.name = "interface",
|
|
|
|
.node = INTERFACE_NODE,
|
|
|
|
.parent_node = CONFIG_NODE,
|
|
|
|
.prompt = "%s(config-if)# ",
|
|
|
|
};
|
|
|
|
|
2021-10-13 17:30:06 +02:00
|
|
|
static int if_config_write_single(const struct lyd_node *dnode, void *arg)
|
|
|
|
{
|
|
|
|
nb_cli_show_dnode_cmds(arg, dnode, false);
|
|
|
|
|
|
|
|
return YANG_ITER_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int if_nb_config_write(struct vty *vty)
|
|
|
|
{
|
|
|
|
yang_dnode_iterate(if_config_write_single, vty, running_config->dnode,
|
|
|
|
"/frr-interface:lib/interface");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-07-29 20:34:56 +02:00
|
|
|
void if_cmd_init(int (*config_write)(struct vty *))
|
2018-05-09 06:34:57 +02:00
|
|
|
{
|
|
|
|
cmd_variable_handler_register(if_var_handlers);
|
|
|
|
|
2021-07-29 20:34:56 +02:00
|
|
|
interface_node.config_write = config_write;
|
|
|
|
install_node(&interface_node);
|
|
|
|
|
2018-05-09 06:34:57 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-10-13 17:30:06 +02:00
|
|
|
void if_cmd_init_default(void)
|
|
|
|
{
|
|
|
|
if_cmd_init(if_nb_config_write);
|
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
/* ------- Northbound callbacks ------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface
|
|
|
|
*/
|
2020-04-04 18:38:51 +02:00
|
|
|
static int lib_interface_create(struct nb_cb_create_args *args)
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
const char *ifname;
|
2019-06-24 01:46:39 +02:00
|
|
|
struct interface *ifp;
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2023-11-29 20:37:23 +01:00
|
|
|
ifname = yang_dnode_get_string(args->dnode, "name");
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
switch (args->event) {
|
2018-05-09 06:34:57 +02:00
|
|
|
case NB_EV_VALIDATE:
|
2021-11-08 11:33:03 +01:00
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
char ifname_ns[XPATH_MAXLEN];
|
|
|
|
char vrfname_ns[XPATH_MAXLEN];
|
|
|
|
|
|
|
|
netns_ifname_split(ifname, ifname_ns, vrfname_ns);
|
|
|
|
|
|
|
|
if (strlen(ifname_ns) > 16) {
|
|
|
|
snprintf(
|
|
|
|
args->errmsg, args->errmsg_len,
|
|
|
|
"Maximum interface name length is 16 characters");
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
if (strlen(vrfname_ns) > 36) {
|
|
|
|
snprintf(
|
|
|
|
args->errmsg, args->errmsg_len,
|
|
|
|
"Maximum VRF name length is 36 characters");
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (strlen(ifname) > 16) {
|
|
|
|
snprintf(
|
|
|
|
args->errmsg, args->errmsg_len,
|
|
|
|
"Maximum interface name length is 16 characters");
|
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2018-05-09 06:34:57 +02:00
|
|
|
case NB_EV_PREPARE:
|
|
|
|
case NB_EV_ABORT:
|
|
|
|
break;
|
|
|
|
case NB_EV_APPLY:
|
2021-11-08 11:33:03 +01:00
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
char ifname_ns[XPATH_MAXLEN];
|
|
|
|
char vrfname_ns[XPATH_MAXLEN];
|
|
|
|
|
|
|
|
netns_ifname_split(ifname, ifname_ns, vrfname_ns);
|
|
|
|
|
|
|
|
ifp = if_get_by_name(ifname_ns, VRF_UNKNOWN,
|
|
|
|
vrfname_ns);
|
|
|
|
} else {
|
|
|
|
ifp = if_get_by_name(ifname, VRF_UNKNOWN,
|
|
|
|
VRF_DEFAULT_NAME);
|
|
|
|
}
|
2019-09-18 19:42:46 +02:00
|
|
|
|
|
|
|
ifp->configured = true;
|
2020-04-04 18:38:51 +02:00
|
|
|
nb_running_set_entry(args->dnode, ifp);
|
2018-05-09 06:34:57 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
static int lib_interface_destroy(struct nb_cb_destroy_args *args)
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
2021-11-05 23:22:07 +01:00
|
|
|
struct vrf *vrf;
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
switch (args->event) {
|
2018-05-09 06:34:57 +02:00
|
|
|
case NB_EV_VALIDATE:
|
2020-04-04 18:38:51 +02:00
|
|
|
ifp = nb_running_get_entry(args->dnode, NULL, true);
|
2018-05-09 06:34:57 +02:00
|
|
|
if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
|
2020-05-15 02:34:12 +02:00
|
|
|
snprintf(args->errmsg, args->errmsg_len,
|
|
|
|
"only inactive interfaces can be deleted");
|
2018-05-09 06:34:57 +02:00
|
|
|
return NB_ERR_VALIDATION;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NB_EV_PREPARE:
|
|
|
|
case NB_EV_ABORT:
|
|
|
|
break;
|
|
|
|
case NB_EV_APPLY:
|
2020-04-04 18:38:51 +02:00
|
|
|
ifp = nb_running_unset_entry(args->dnode);
|
2021-11-05 23:22:07 +01:00
|
|
|
vrf = ifp->vrf;
|
2019-09-18 19:42:46 +02:00
|
|
|
|
|
|
|
ifp->configured = false;
|
2019-10-30 01:24:10 +01:00
|
|
|
if_delete(&ifp);
|
2021-11-05 23:22:07 +01:00
|
|
|
|
|
|
|
if (!vrf_is_enabled(vrf))
|
|
|
|
vrf_delete(vrf);
|
2018-05-09 06:34:57 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-12 23:35:04 +02:00
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface
|
|
|
|
*/
|
2020-04-04 18:38:51 +02:00
|
|
|
static const void *lib_interface_get_next(struct nb_cb_get_next_args *args)
|
2019-09-12 23:35:04 +02:00
|
|
|
{
|
|
|
|
struct vrf *vrf;
|
2020-04-04 18:38:51 +02:00
|
|
|
struct interface *pif = (struct interface *)args->list_entry;
|
2019-09-12 23:35:04 +02:00
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
if (args->list_entry == NULL) {
|
2019-09-12 23:35:04 +02:00
|
|
|
vrf = RB_MIN(vrf_name_head, &vrfs_by_name);
|
|
|
|
assert(vrf);
|
|
|
|
pif = RB_MIN(if_name_head, &vrf->ifaces_by_name);
|
|
|
|
} else {
|
2021-10-13 14:06:38 +02:00
|
|
|
vrf = pif->vrf;
|
2019-09-12 23:35:04 +02:00
|
|
|
pif = RB_NEXT(if_name_head, pif);
|
|
|
|
/* if no more interfaces, switch to next vrf */
|
|
|
|
while (pif == NULL) {
|
|
|
|
vrf = RB_NEXT(vrf_name_head, vrf);
|
|
|
|
if (!vrf)
|
|
|
|
return NULL;
|
|
|
|
pif = RB_MIN(if_name_head, &vrf->ifaces_by_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pif;
|
|
|
|
}
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
static int lib_interface_get_keys(struct nb_cb_get_keys_args *args)
|
2019-09-12 23:35:04 +02:00
|
|
|
{
|
2020-04-04 18:38:51 +02:00
|
|
|
const struct interface *ifp = args->list_entry;
|
2019-09-12 23:35:04 +02:00
|
|
|
|
2021-11-08 11:33:03 +01:00
|
|
|
args->keys->num = 1;
|
|
|
|
|
|
|
|
if (vrf_is_backend_netns())
|
|
|
|
snprintf(args->keys->key[0], sizeof(args->keys->key[0]),
|
|
|
|
"%s:%s", ifp->vrf->name, ifp->name);
|
|
|
|
else
|
|
|
|
snprintf(args->keys->key[0], sizeof(args->keys->key[0]), "%s",
|
|
|
|
ifp->name);
|
2019-09-12 23:35:04 +02:00
|
|
|
|
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
static const void *
|
|
|
|
lib_interface_lookup_entry(struct nb_cb_lookup_entry_args *args)
|
2019-09-12 23:35:04 +02:00
|
|
|
{
|
2021-11-08 11:33:03 +01:00
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
char ifname[XPATH_MAXLEN];
|
|
|
|
char vrfname[XPATH_MAXLEN];
|
|
|
|
struct vrf *vrf;
|
|
|
|
|
|
|
|
netns_ifname_split(args->keys->key[0], ifname, vrfname);
|
2019-09-12 23:35:04 +02:00
|
|
|
|
2021-11-08 11:33:03 +01:00
|
|
|
vrf = vrf_lookup_by_name(vrfname);
|
|
|
|
|
|
|
|
return vrf ? if_lookup_by_name(ifname, vrf->vrf_id) : NULL;
|
|
|
|
} else {
|
|
|
|
return if_lookup_by_name_all_vrf(args->keys->key[0]);
|
|
|
|
}
|
2019-09-12 23:35:04 +02:00
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/description
|
|
|
|
*/
|
2020-04-04 18:38:51 +02:00
|
|
|
static int lib_interface_description_modify(struct nb_cb_modify_args *args)
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
const char *description;
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
if (args->event != NB_EV_APPLY)
|
2018-05-09 06:34:57 +02:00
|
|
|
return NB_OK;
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
ifp = nb_running_get_entry(args->dnode, NULL, true);
|
2022-12-02 17:10:24 +01:00
|
|
|
XFREE(MTYPE_IFDESC, ifp->desc);
|
2020-04-04 18:38:51 +02:00
|
|
|
description = yang_dnode_get_string(args->dnode, NULL);
|
2022-12-02 17:10:24 +01:00
|
|
|
ifp->desc = XSTRDUP(MTYPE_IFDESC, description);
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
static int lib_interface_description_destroy(struct nb_cb_destroy_args *args)
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
2018-05-09 06:34:57 +02:00
|
|
|
struct interface *ifp;
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
if (args->event != NB_EV_APPLY)
|
2018-05-09 06:34:57 +02:00
|
|
|
return NB_OK;
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
ifp = nb_running_get_entry(args->dnode, NULL, true);
|
2022-12-02 17:10:24 +01:00
|
|
|
XFREE(MTYPE_IFDESC, ifp->desc);
|
2018-05-09 06:34:57 +02:00
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
return NB_OK;
|
|
|
|
}
|
|
|
|
|
2024-11-24 09:00:37 +01:00
|
|
|
static enum nb_error __return_ok(const struct nb_node *nb_node, const void *list_entry,
|
|
|
|
struct lyd_node *parent)
|
2021-11-08 11:33:03 +01:00
|
|
|
{
|
2024-11-24 09:00:37 +01:00
|
|
|
return NB_OK;
|
2021-11-08 11:33:03 +01:00
|
|
|
}
|
|
|
|
|
2020-02-19 22:26:41 +01:00
|
|
|
/*
|
2024-11-24 09:00:37 +01:00
|
|
|
* XPath: /frr-interface:lib/interface/vrf
|
2020-02-19 22:26:41 +01:00
|
|
|
*/
|
2024-11-24 09:00:37 +01:00
|
|
|
static enum nb_error lib_interface_vrf_get(const struct nb_node *nb_node, const void *list_entry,
|
|
|
|
struct lyd_node *parent)
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
2024-11-24 09:00:37 +01:00
|
|
|
const struct lysc_node *snode = nb_node->snode;
|
|
|
|
const struct interface *ifp = list_entry;
|
2020-02-19 22:26:41 +01:00
|
|
|
|
2024-11-24 09:00:37 +01:00
|
|
|
if (lyd_new_term(parent, snode->module, snode->name, ifp->vrf->name, LYD_NEW_PATH_UPDATE,
|
|
|
|
NULL))
|
|
|
|
return NB_ERR_RESOURCE;
|
|
|
|
return NB_OK;
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-11-24 09:00:37 +01:00
|
|
|
* XPath: /frr-interface:lib/interface/state/if-index
|
2020-02-19 22:26:41 +01:00
|
|
|
*/
|
2024-11-24 09:00:37 +01:00
|
|
|
static enum nb_error lib_interface_state_if_index_get(const struct nb_node *nb_node,
|
|
|
|
const void *list_entry,
|
|
|
|
struct lyd_node *parent)
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
2024-11-24 09:00:37 +01:00
|
|
|
const struct lysc_node *snode = nb_node->snode;
|
|
|
|
const struct interface *ifp = list_entry;
|
|
|
|
int32_t value = ifp->ifindex;
|
2020-02-19 22:26:41 +01:00
|
|
|
|
2024-11-24 09:00:37 +01:00
|
|
|
if (lyd_new_term_bin(parent, snode->module, snode->name, &value, sizeof(value),
|
|
|
|
LYD_NEW_PATH_UPDATE, NULL))
|
|
|
|
return NB_ERR_RESOURCE;
|
|
|
|
return NB_OK;
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2024-11-24 09:00:37 +01:00
|
|
|
* XPath: /frr-interface:lib/interface/state/mtu[6]
|
2020-02-19 22:26:41 +01:00
|
|
|
*/
|
2024-11-24 09:00:37 +01:00
|
|
|
static enum nb_error lib_interface_state_mtu_get(const struct nb_node *nb_node,
|
|
|
|
const void *list_entry, struct lyd_node *parent)
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
2024-11-24 09:00:37 +01:00
|
|
|
const struct lysc_node *snode = nb_node->snode;
|
|
|
|
const struct interface *ifp = list_entry;
|
|
|
|
uint32_t value = ifp->mtu;
|
2020-02-19 22:26:41 +01:00
|
|
|
|
2024-11-24 09:00:37 +01:00
|
|
|
if (lyd_new_term_bin(parent, snode->module, snode->name, &value, sizeof(value),
|
|
|
|
LYD_NEW_PATH_UPDATE, NULL))
|
|
|
|
return NB_ERR_RESOURCE;
|
|
|
|
return NB_OK;
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/state/speed
|
|
|
|
*/
|
2024-11-24 09:00:37 +01:00
|
|
|
static enum nb_error lib_interface_state_speed_get(const struct nb_node *nb_node,
|
|
|
|
const void *list_entry, struct lyd_node *parent)
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
2024-11-24 09:00:37 +01:00
|
|
|
const struct lysc_node *snode = nb_node->snode;
|
|
|
|
const struct interface *ifp = list_entry;
|
|
|
|
uint32_t value = ifp->speed;
|
2020-02-19 22:26:41 +01:00
|
|
|
|
2024-11-24 09:00:37 +01:00
|
|
|
if (lyd_new_term_bin(parent, snode->module, snode->name, &value, sizeof(value),
|
|
|
|
LYD_NEW_PATH_UPDATE, NULL))
|
|
|
|
return NB_ERR_RESOURCE;
|
|
|
|
return NB_OK;
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/state/metric
|
|
|
|
*/
|
2024-11-24 09:00:37 +01:00
|
|
|
static enum nb_error lib_interface_state_metric_get(const struct nb_node *nb_node,
|
|
|
|
const void *list_entry, struct lyd_node *parent)
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
2024-11-24 09:00:37 +01:00
|
|
|
const struct lysc_node *snode = nb_node->snode;
|
|
|
|
const struct interface *ifp = list_entry;
|
|
|
|
uint32_t value = ifp->metric;
|
2020-02-19 22:26:41 +01:00
|
|
|
|
2024-11-24 09:00:37 +01:00
|
|
|
if (lyd_new_term_bin(parent, snode->module, snode->name, &value, sizeof(value),
|
|
|
|
LYD_NEW_PATH_UPDATE, NULL))
|
|
|
|
return NB_ERR_RESOURCE;
|
|
|
|
return NB_OK;
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XPath: /frr-interface:lib/interface/state/phy-address
|
|
|
|
*/
|
2020-04-04 18:38:51 +02:00
|
|
|
static struct yang_data *
|
|
|
|
lib_interface_state_phy_address_get_elem(struct nb_cb_get_elem_args *args)
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
2020-04-04 18:38:51 +02:00
|
|
|
const struct interface *ifp = args->list_entry;
|
2020-02-19 22:26:41 +01:00
|
|
|
struct ethaddr macaddr;
|
|
|
|
|
|
|
|
memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN);
|
|
|
|
|
2020-04-04 18:38:51 +02:00
|
|
|
return yang_data_new_mac(args->xpath, &macaddr);
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
|
2018-07-08 03:04:33 +02:00
|
|
|
/* clang-format off */
|
2024-02-04 20:52:47 +01:00
|
|
|
|
|
|
|
/* cli_show callbacks are kept here for daemons not yet converted to mgmtd */
|
2018-07-08 03:04:33 +02:00
|
|
|
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,
|
2021-08-08 21:38:50 +02:00
|
|
|
.cli_show_end = cli_show_interface_end,
|
2024-03-06 20:41:35 +01:00
|
|
|
.cli_cmp = cli_cmp_interface,
|
2019-09-12 23:35:04 +02:00
|
|
|
.get_next = lib_interface_get_next,
|
|
|
|
.get_keys = lib_interface_get_keys,
|
|
|
|
.lookup_entry = lib_interface_lookup_entry,
|
2019-06-12 19:13:30 +02:00
|
|
|
},
|
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
|
|
|
},
|
2021-11-08 11:33:03 +01:00
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/vrf",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = lib_interface_vrf_get,
|
2021-11-08 11:33:03 +01:00
|
|
|
}
|
|
|
|
},
|
2020-02-19 22:26:41 +01:00
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/if-index",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = lib_interface_state_if_index_get,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/mtu",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = lib_interface_state_mtu_get,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/mtu6",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = lib_interface_state_mtu_get,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/speed",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = lib_interface_state_speed_get,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/metric",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = lib_interface_state_metric_get,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/flags",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = __return_ok,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/type",
|
|
|
|
.cbs = {
|
2024-11-24 09:00:37 +01:00
|
|
|
.get = __return_ok,
|
2020-02-19 22:26:41 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/state/phy-address",
|
|
|
|
.cbs = {
|
|
|
|
.get_elem = lib_interface_state_phy_address_get_elem,
|
|
|
|
}
|
|
|
|
},
|
2018-07-08 03:04:33 +02:00
|
|
|
{
|
|
|
|
.xpath = NULL,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
2024-02-04 20:52:47 +01:00
|
|
|
|
|
|
|
const struct frr_yang_module_info frr_interface_cli_info = {
|
|
|
|
.name = "frr-interface",
|
|
|
|
.ignore_cfg_cbs = true,
|
|
|
|
.nodes = {
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface",
|
|
|
|
.cbs = {
|
|
|
|
.cli_show = cli_show_interface,
|
|
|
|
.cli_show_end = cli_show_interface_end,
|
2024-03-06 20:41:35 +01:00
|
|
|
.cli_cmp = cli_cmp_interface,
|
2024-02-04 20:52:47 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = "/frr-interface:lib/interface/description",
|
|
|
|
.cbs = {
|
|
|
|
.cli_show = cli_show_interface_desc,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.xpath = NULL,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|