2003-08-01 02:24:13 +02:00
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
/*
|
|
|
|
|
* Interface functions.
|
|
|
|
|
* Copyright (C) 1997, 98 Kunihiro Ishiguro
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GNU Zebra.
|
|
|
|
|
*
|
|
|
|
|
* GNU Zebra is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published
|
|
|
|
|
* by the Free Software Foundation; either version 2, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with GNU Zebra; see the file COPYING. If not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <zebra.h>
|
|
|
|
|
|
|
|
|
|
#include "linklist.h"
|
|
|
|
|
#include "vector.h"
|
|
|
|
|
#include "vty.h"
|
|
|
|
|
#include "command.h"
|
|
|
|
|
#include "if.h"
|
|
|
|
|
#include "sockunion.h"
|
|
|
|
|
#include "prefix.h"
|
|
|
|
|
#include "memory.h"
|
|
|
|
|
#include "table.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "str.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
|
|
/* Master list of interfaces. */
|
|
|
|
|
struct list *iflist;
|
|
|
|
|
|
|
|
|
|
/* One for each program. This structure is needed to store hooks. */
|
|
|
|
|
struct if_master
|
|
|
|
|
{
|
|
|
|
|
int (*if_new_hook) (struct interface *);
|
|
|
|
|
int (*if_delete_hook) (struct interface *);
|
|
|
|
|
} if_master;
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2003-08-01 02:24:13 +02:00
|
|
|
|
int
|
|
|
|
|
if_cmp_func (struct interface *ifp1, struct interface *ifp2)
|
|
|
|
|
{
|
|
|
|
|
unsigned int l1, l2;
|
|
|
|
|
long int x1, x2;
|
|
|
|
|
char *p1, *p2;
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
p1 = ifp1->name;
|
|
|
|
|
p2 = ifp2->name;
|
|
|
|
|
|
2003-09-24 01:46:01 +02:00
|
|
|
|
while (*p1 && *p2) {
|
2003-08-01 02:24:13 +02:00
|
|
|
|
/* look up to any number */
|
|
|
|
|
l1 = strcspn(p1, "0123456789");
|
|
|
|
|
l2 = strcspn(p2, "0123456789");
|
|
|
|
|
|
|
|
|
|
/* name lengths are different -> compare names */
|
|
|
|
|
if (l1 != l2)
|
|
|
|
|
return (strcmp(p1, p2));
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
/* names are different -> compare them */
|
|
|
|
|
if (res)
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
|
|
/* with identical name part, go to numeric part */
|
|
|
|
|
p1 += l1;
|
|
|
|
|
p2 += l1;
|
|
|
|
|
|
2004-07-09 14:24:42 +02:00
|
|
|
|
if (!*p1)
|
|
|
|
|
return -1;
|
|
|
|
|
if (!*p2)
|
|
|
|
|
return 1;
|
|
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
|
x1 = strtol(p1, &p1, 10);
|
|
|
|
|
x2 = strtol(p2, &p2, 10);
|
|
|
|
|
|
|
|
|
|
/* let's compare numbers now */
|
|
|
|
|
if (x1 < x2)
|
|
|
|
|
return -1;
|
|
|
|
|
if (x1 > x2)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
/* numbers were equal, lets do it again..
|
|
|
|
|
(it happens with name like "eth123.456:789") */
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
/* Create new interface structure. */
|
|
|
|
|
struct interface *
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
|
if_create (const char *name, int namelen)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
|
ifp = XCALLOC (MTYPE_IF, sizeof (struct interface));
|
|
|
|
|
ifp->ifindex = IFINDEX_INTERNAL;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
|
assert (name);
|
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
|
|
|
|
assert (namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */
|
2003-08-01 02:24:13 +02:00
|
|
|
|
strncpy (ifp->name, name, namelen);
|
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->name[namelen] = '\0';
|
2003-12-21 10:51:42 +01:00
|
|
|
|
if (if_lookup_by_name(ifp->name) == NULL)
|
|
|
|
|
listnode_add_sort (iflist, 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
|
|
|
|
else
|
|
|
|
|
zlog_err("if_create(%s): corruption detected -- interface with this "
|
|
|
|
|
"name exists already!", ifp->name);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
ifp->connected = list_new ();
|
|
|
|
|
ifp->connected->del = (void (*) (void *)) connected_free;
|
|
|
|
|
|
|
|
|
|
if (if_master.if_new_hook)
|
|
|
|
|
(*if_master.if_new_hook) (ifp);
|
|
|
|
|
|
|
|
|
|
return 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
|
|
|
|
/* Delete interface structure. */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
void
|
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
|
|
|
|
if_delete_retain (struct interface *ifp)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
if (if_master.if_delete_hook)
|
|
|
|
|
(*if_master.if_delete_hook) (ifp);
|
|
|
|
|
|
|
|
|
|
/* Free connected address list */
|
|
|
|
|
list_delete (ifp->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. */
|
|
|
|
|
void
|
|
|
|
|
if_delete (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
listnode_delete (iflist, ifp);
|
|
|
|
|
|
|
|
|
|
if_delete_retain(ifp);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
|
|
XFREE (MTYPE_IF, ifp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add hook to interface master. */
|
|
|
|
|
void
|
|
|
|
|
if_add_hook (int type, int (*func)(struct interface *ifp))
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case IF_NEW_HOOK:
|
|
|
|
|
if_master.if_new_hook = func;
|
|
|
|
|
break;
|
|
|
|
|
case IF_DELETE_HOOK:
|
|
|
|
|
if_master.if_delete_hook = func;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interface existance check by index. */
|
|
|
|
|
struct interface *
|
|
|
|
|
if_lookup_by_index (unsigned int index)
|
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
if (ifp->ifindex == index)
|
|
|
|
|
return ifp;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
ifindex2ifname (unsigned int index)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
return ((ifp = if_lookup_by_index(index)) != NULL) ?
|
|
|
|
|
ifp->name : (char *)"unknown";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
|
ifname2ifindex (const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
return ((ifp = if_lookup_by_name(name)) != NULL) ? ifp->ifindex : 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interface existance check by interface name. */
|
|
|
|
|
struct interface *
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
|
if_lookup_by_name (const char *name)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
2005-04-03 05:40:52 +02:00
|
|
|
|
if (strcmp(name, ifp->name) == 0)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
return ifp;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-03 00:50:38 +02:00
|
|
|
|
struct interface *
|
|
|
|
|
if_lookup_by_name_len(const char *name, size_t namelen)
|
|
|
|
|
{
|
|
|
|
|
struct listnode *node;
|
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
|
|
|
|
|
|
|
|
|
if (namelen > INTERFACE_NAMSIZ)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
|
2005-04-03 00:50:38 +02:00
|
|
|
|
{
|
|
|
|
|
if (!memcmp(name, ifp->name, namelen) && (ifp->name[namelen] == '\0'))
|
|
|
|
|
return ifp;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
/* Lookup interface by IPv4 address. */
|
|
|
|
|
struct interface *
|
|
|
|
|
if_lookup_exact_address (struct in_addr src)
|
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
|
|
|
|
struct listnode *cnode;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
struct interface *ifp;
|
|
|
|
|
struct prefix *p;
|
|
|
|
|
struct connected *c;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
p = c->address;
|
|
|
|
|
|
|
|
|
|
if (p && p->family == AF_INET)
|
|
|
|
|
{
|
|
|
|
|
if (IPV4_ADDR_SAME (&p->u.prefix4, &src))
|
|
|
|
|
return ifp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Lookup interface by IPv4 address. */
|
|
|
|
|
struct interface *
|
|
|
|
|
if_lookup_address (struct in_addr src)
|
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
struct prefix addr;
|
2004-10-19 21:44:43 +02:00
|
|
|
|
int bestlen = 0;
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *cnode;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
struct interface *ifp;
|
|
|
|
|
struct prefix *p;
|
|
|
|
|
struct connected *c;
|
|
|
|
|
struct interface *match;
|
|
|
|
|
|
|
|
|
|
addr.family = AF_INET;
|
|
|
|
|
addr.u.prefix4 = src;
|
|
|
|
|
addr.prefixlen = IPV4_MAX_BITLEN;
|
|
|
|
|
|
|
|
|
|
match = NULL;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
if (c->address && (c->address->family == AF_INET))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
if (CONNECTED_POINTOPOINT_HOST(c))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
/* PTP links are conventionally identified
|
|
|
|
|
by the address of the far end - MAG */
|
|
|
|
|
if (IPV4_ADDR_SAME (&c->destination->u.prefix4, &src))
|
2003-09-29 21:54:53 +02:00
|
|
|
|
return ifp;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
2004-10-19 21:44:43 +02:00
|
|
|
|
else
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
p = c->address;
|
|
|
|
|
|
|
|
|
|
if (prefix_match (p, &addr) && p->prefixlen > bestlen)
|
2003-09-29 21:54:53 +02:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
bestlen = p->prefixlen;
|
2003-09-29 21:54:53 +02:00
|
|
|
|
match = ifp;
|
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return match;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get interface by name if given name interface doesn't exist create
|
|
|
|
|
one. */
|
|
|
|
|
struct interface *
|
2004-10-10 Paul Jakma <paul@dishone.st>
* version.h.in: (pid_output*) add const qualifier.
* command.h: Change DEFUN func to take const char *[] rather
than char **, to begin process of fixing compile warnings in lib/.
Nearly all other changes in this commit follow from this change.
* buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take
const void * and cast an automatic const char *p to it.
(buffer_putstr) add const
* command.c: (zencrypt) const qualifier
(cmd_execute_command_real) ditto
(cmd_execute_command_strict) ditto
(config_log_file) ditto.
Fix leak of getcwd() returned string.
* memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname.
* distribute.{c,h}: Update with const qualifier.
(distribute_free) use MTYPE_DISTRIBUTE_IFNAME
(distribute_lookup) Cast to char *, note that it's ok.
(distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME.
(distribute_get) Cast to char *, note that it's ok.
* filter.c: Update with const qualifier.
* if.{c,h}: ditto.
* if_rmap.{c,h}: ditto.
(if_rmap_lookup) Cast to char *, note that it's ok.
(if_rmap_get) ditto.
* log.{c,h}: Update with const qualifier.
* plist.{c,h}: ditto.
* routemap.{c,h}: ditto.
* smux.{c,h}: ditto. Fix some signed/unsigned comparisons.
* sockopt.c: (getsockopt_cmsg_data) add return for error case.
* vty.c: Update with const qualifier.
2004-10-10 13:56:56 +02:00
|
|
|
|
if_get_by_name (const char *name)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
2005-04-03 00:50:38 +02:00
|
|
|
|
return ((ifp = if_lookup_by_name(name)) != NULL) ? ifp :
|
2005-04-03 05:40:52 +02:00
|
|
|
|
if_create(name, strlen(name));
|
2005-04-03 00:50:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct interface *
|
|
|
|
|
if_get_by_name_len(const char *name, size_t namelen)
|
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
return ((ifp = if_lookup_by_name_len(name, namelen)) != NULL) ? ifp :
|
|
|
|
|
if_create(name, namelen);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Does interface up ? */
|
|
|
|
|
int
|
|
|
|
|
if_is_up (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
return ifp->flags & IFF_UP;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 22:03:13 +01:00
|
|
|
|
/* Is interface running? */
|
|
|
|
|
int
|
|
|
|
|
if_is_running (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
return ifp->flags & IFF_RUNNING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Is the interface operative, eg. either UP & RUNNING
|
|
|
|
|
or UP & !ZEBRA_INTERFACE_LINK_DETECTION */
|
|
|
|
|
int
|
|
|
|
|
if_is_operative (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
return ((ifp->flags & IFF_UP) &&
|
|
|
|
|
(ifp->flags & IFF_RUNNING || !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)));
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
/* Is this loopback interface ? */
|
|
|
|
|
int
|
|
|
|
|
if_is_loopback (struct interface *ifp)
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Does this interface support broadcast ? */
|
|
|
|
|
int
|
|
|
|
|
if_is_broadcast (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
return ifp->flags & IFF_BROADCAST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Does this interface support broadcast ? */
|
|
|
|
|
int
|
|
|
|
|
if_is_pointopoint (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
return ifp->flags & IFF_POINTOPOINT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Does this interface support multicast ? */
|
|
|
|
|
int
|
|
|
|
|
if_is_multicast (struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
#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) \
|
|
|
|
|
strlcat (logbuf, ",", BUFSIZ); \
|
|
|
|
|
else \
|
|
|
|
|
separator = 1; \
|
|
|
|
|
strlcat (logbuf, STR, BUFSIZ); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strlcpy (logbuf, " <", BUFSIZ);
|
|
|
|
|
IFF_OUT_LOG (IFF_UP, "UP");
|
|
|
|
|
IFF_OUT_LOG (IFF_BROADCAST, "BROADCAST");
|
|
|
|
|
IFF_OUT_LOG (IFF_DEBUG, "DEBUG");
|
|
|
|
|
IFF_OUT_LOG (IFF_LOOPBACK, "LOOPBACK");
|
|
|
|
|
IFF_OUT_LOG (IFF_POINTOPOINT, "POINTOPOINT");
|
|
|
|
|
IFF_OUT_LOG (IFF_NOTRAILERS, "NOTRAILERS");
|
|
|
|
|
IFF_OUT_LOG (IFF_RUNNING, "RUNNING");
|
|
|
|
|
IFF_OUT_LOG (IFF_NOARP, "NOARP");
|
|
|
|
|
IFF_OUT_LOG (IFF_PROMISC, "PROMISC");
|
|
|
|
|
IFF_OUT_LOG (IFF_ALLMULTI, "ALLMULTI");
|
|
|
|
|
IFF_OUT_LOG (IFF_OACTIVE, "OACTIVE");
|
|
|
|
|
IFF_OUT_LOG (IFF_SIMPLEX, "SIMPLEX");
|
|
|
|
|
IFF_OUT_LOG (IFF_LINK0, "LINK0");
|
|
|
|
|
IFF_OUT_LOG (IFF_LINK1, "LINK1");
|
|
|
|
|
IFF_OUT_LOG (IFF_LINK2, "LINK2");
|
|
|
|
|
IFF_OUT_LOG (IFF_MULTICAST, "MULTICAST");
|
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");
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
|
|
strlcat (logbuf, ">", BUFSIZ);
|
|
|
|
|
|
|
|
|
|
return logbuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For debugging */
|
|
|
|
|
void
|
|
|
|
|
if_dump (struct interface *ifp)
|
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
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 connected *c;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
2004-05-08 07:00:31 +02:00
|
|
|
|
zlog_info ("Interface %s index %d metric %d mtu %d "
|
|
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
|
"mtu6 %d "
|
|
|
|
|
#endif /* HAVE_IPV6 */
|
|
|
|
|
"%s",
|
2002-12-13 21:15:29 +01:00
|
|
|
|
ifp->name, ifp->ifindex, ifp->metric, ifp->mtu,
|
2004-05-08 07:00:31 +02:00
|
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
|
ifp->mtu6,
|
|
|
|
|
#endif /* HAVE_IPV6 */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
if_flag_dump (ifp->flags));
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, c))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interface printing for all interface. */
|
|
|
|
|
void
|
|
|
|
|
if_dump_all ()
|
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
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
|
|
|
|
void *p;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (iflist, node, p))
|
|
|
|
|
if_dump (p);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEFUN (interface_desc,
|
|
|
|
|
interface_desc_cmd,
|
|
|
|
|
"description .LINE",
|
|
|
|
|
"Interface specific description\n"
|
|
|
|
|
"Characters describing this interface\n")
|
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
|
|
|
|
|
ifp = vty->index;
|
|
|
|
|
if (ifp->desc)
|
2005-01-29 19:19:13 +01:00
|
|
|
|
XFREE (MTYPE_TMP, ifp->desc);
|
|
|
|
|
ifp->desc = argv_concat(argv, argc, 0);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEFUN (no_interface_desc,
|
|
|
|
|
no_interface_desc_cmd,
|
|
|
|
|
"no description",
|
|
|
|
|
NO_STR
|
|
|
|
|
"Interface specific description\n")
|
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
ifp = vty->index;
|
|
|
|
|
if (ifp->desc)
|
|
|
|
|
XFREE (0, ifp->desc);
|
|
|
|
|
ifp->desc = NULL;
|
|
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* See also wrapper function zebra_interface() in zebra/interface.c */
|
|
|
|
|
DEFUN (interface,
|
|
|
|
|
interface_cmd,
|
|
|
|
|
"interface IFNAME",
|
|
|
|
|
"Select an interface to configure\n"
|
|
|
|
|
"Interface's name\n")
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
size_t sl;
|
|
|
|
|
|
|
|
|
|
if ((sl = strlen(argv[0])) > INTERFACE_NAMSIZ)
|
|
|
|
|
{
|
|
|
|
|
vty_out (vty, "%% Interface name %s is invalid: length exceeds "
|
|
|
|
|
"%d characters%s",
|
|
|
|
|
argv[0], INTERFACE_NAMSIZ, VTY_NEWLINE);
|
|
|
|
|
return CMD_WARNING;
|
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
2005-04-03 00:50:38 +02:00
|
|
|
|
ifp = if_get_by_name_len(argv[0], sl);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
|
|
vty->index = ifp;
|
|
|
|
|
vty->node = INTERFACE_NODE;
|
|
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-23 11:25:20 +02:00
|
|
|
|
DEFUN_NOSH (no_interface,
|
|
|
|
|
no_interface_cmd,
|
|
|
|
|
"no interface IFNAME",
|
|
|
|
|
NO_STR
|
|
|
|
|
"Delete a pseudo interface's configuration\n"
|
|
|
|
|
"Interface's name\n")
|
|
|
|
|
{
|
|
|
|
|
// deleting interface
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
ifp = if_lookup_by_name (argv[0]);
|
|
|
|
|
|
|
|
|
|
if (ifp == NULL)
|
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
|
|
|
|
{
|
|
|
|
|
vty_out (vty, "%% Interface %s does not exist%s", argv[0], VTY_NEWLINE);
|
|
|
|
|
return CMD_WARNING;
|
|
|
|
|
}
|
2003-05-23 11:25:20 +02:00
|
|
|
|
|
2003-05-24 08:40:04 +02:00
|
|
|
|
if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
|
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
|
|
|
|
{
|
|
|
|
|
vty_out (vty, "%% Only inactive interfaces can be deleted%s",
|
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
return CMD_WARNING;
|
|
|
|
|
}
|
2003-05-23 11:25:20 +02:00
|
|
|
|
|
|
|
|
|
if_delete(ifp);
|
|
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
/* For debug purpose. */
|
|
|
|
|
DEFUN (show_address,
|
|
|
|
|
show_address_cmd,
|
|
|
|
|
"show address",
|
|
|
|
|
SHOW_STR
|
|
|
|
|
"address\n")
|
|
|
|
|
{
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *node;
|
|
|
|
|
struct listnode *node2;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
struct interface *ifp;
|
|
|
|
|
struct connected *ifc;
|
|
|
|
|
struct prefix *p;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
{
|
|
|
|
|
p = ifc->address;
|
|
|
|
|
|
|
|
|
|
if (p->family == AF_INET)
|
|
|
|
|
vty_out (vty, "%s/%d%s", inet_ntoa (p->u.prefix4), p->prefixlen,
|
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate connected structure. */
|
|
|
|
|
struct connected *
|
|
|
|
|
connected_new ()
|
|
|
|
|
{
|
|
|
|
|
struct connected *new = XMALLOC (MTYPE_CONNECTED, sizeof (struct connected));
|
|
|
|
|
memset (new, 0, sizeof (struct connected));
|
|
|
|
|
return new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free connected structure. */
|
|
|
|
|
void
|
|
|
|
|
connected_free (struct connected *connected)
|
|
|
|
|
{
|
|
|
|
|
if (connected->address)
|
|
|
|
|
prefix_free (connected->address);
|
|
|
|
|
|
|
|
|
|
if (connected->destination)
|
|
|
|
|
prefix_free (connected->destination);
|
|
|
|
|
|
|
|
|
|
if (connected->label)
|
|
|
|
|
free (connected->label);
|
|
|
|
|
|
|
|
|
|
XFREE (MTYPE_CONNECTED, connected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print if_addr structure. */
|
|
|
|
|
void
|
|
|
|
|
connected_log (struct connected *connected, char *str)
|
|
|
|
|
{
|
|
|
|
|
struct prefix *p;
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
char logbuf[BUFSIZ];
|
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
|
|
ifp = connected->ifp;
|
|
|
|
|
p = connected->address;
|
|
|
|
|
|
|
|
|
|
snprintf (logbuf, BUFSIZ, "%s interface %s %s %s/%d ",
|
|
|
|
|
str, ifp->name, prefix_family_str (p),
|
|
|
|
|
inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
|
|
|
|
|
p->prefixlen);
|
|
|
|
|
|
|
|
|
|
p = connected->destination;
|
|
|
|
|
if (p)
|
|
|
|
|
{
|
|
|
|
|
strncat (logbuf, inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
|
|
|
|
|
BUFSIZ - strlen(logbuf));
|
|
|
|
|
}
|
|
|
|
|
zlog (NULL, LOG_INFO, logbuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If two connected address has same prefix return 1. */
|
|
|
|
|
int
|
|
|
|
|
connected_same_prefix (struct prefix *p1, struct prefix *p2)
|
|
|
|
|
{
|
|
|
|
|
if (p1->family == p2->family)
|
|
|
|
|
{
|
|
|
|
|
if (p1->family == AF_INET &&
|
|
|
|
|
IPV4_ADDR_SAME (&p1->u.prefix4, &p2->u.prefix4))
|
|
|
|
|
return 1;
|
|
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
|
if (p1->family == AF_INET6 &&
|
|
|
|
|
IPV6_ADDR_SAME (&p1->u.prefix6, &p2->u.prefix6))
|
|
|
|
|
return 1;
|
|
|
|
|
#endif /* HAVE_IPV6 */
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct connected *
|
|
|
|
|
connected_delete_by_prefix (struct interface *ifp, struct prefix *p)
|
|
|
|
|
{
|
|
|
|
|
struct listnode *node;
|
|
|
|
|
struct listnode *next;
|
|
|
|
|
struct connected *ifc;
|
|
|
|
|
|
|
|
|
|
/* In case of same prefix come, replace it with new one. */
|
|
|
|
|
for (node = listhead (ifp->connected); node; node = next)
|
|
|
|
|
{
|
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
|
|
|
|
ifc = listgetdata (node);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
next = node->next;
|
|
|
|
|
|
|
|
|
|
if (connected_same_prefix (ifc->address, p))
|
|
|
|
|
{
|
|
|
|
|
listnode_delete (ifp->connected, ifc);
|
|
|
|
|
return ifc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 21:50:29 +01:00
|
|
|
|
/* Find the IPv4 address on our side that will be used when packets
|
|
|
|
|
are sent to dst. */
|
|
|
|
|
struct connected *
|
|
|
|
|
connected_lookup_address (struct interface *ifp, struct in_addr dst)
|
|
|
|
|
{
|
|
|
|
|
struct prefix addr;
|
2004-09-23 21:18:23 +02:00
|
|
|
|
struct listnode *cnode;
|
2002-12-13 21:50:29 +01:00
|
|
|
|
struct prefix *p;
|
|
|
|
|
struct connected *c;
|
|
|
|
|
struct connected *match;
|
|
|
|
|
|
|
|
|
|
addr.family = AF_INET;
|
|
|
|
|
addr.u.prefix4 = dst;
|
|
|
|
|
addr.prefixlen = IPV4_MAX_BITLEN;
|
|
|
|
|
|
|
|
|
|
match = NULL;
|
|
|
|
|
|
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
|
|
|
|
for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
|
2002-12-13 21:50:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
if (c->address && (c->address->family == AF_INET))
|
|
|
|
|
{
|
|
|
|
|
if (CONNECTED_POINTOPOINT_HOST(c))
|
2002-12-13 21:50:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
/* PTP links are conventionally identified
|
|
|
|
|
by the address of the far end - MAG */
|
|
|
|
|
if (IPV4_ADDR_SAME (&c->destination->u.prefix4, &dst))
|
2002-12-13 21:50:29 +01:00
|
|
|
|
return c;
|
|
|
|
|
}
|
2004-10-19 21:44:43 +02:00
|
|
|
|
else
|
2002-12-13 21:50:29 +01:00
|
|
|
|
{
|
2004-10-19 21:44:43 +02:00
|
|
|
|
p = c->address;
|
|
|
|
|
|
|
|
|
|
if (prefix_match (p, &addr) &&
|
|
|
|
|
(!match || (p->prefixlen > match->address->prefixlen)))
|
|
|
|
|
match = c;
|
2002-12-13 21:50:29 +01:00
|
|
|
|
}
|
2004-10-19 21:44:43 +02:00
|
|
|
|
}
|
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. */
|
|
|
|
|
listnode_add (ifp->connected, ifc);
|
|
|
|
|
return ifc;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
|
#ifndef HAVE_IF_NAMETOINDEX
|
|
|
|
|
unsigned int
|
|
|
|
|
if_nametoindex (const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
2005-04-03 01:05:56 +02:00
|
|
|
|
return ((ifp = if_lookup_by_name_len(name, strnlen(name, IFNAMSIZ))) != NULL)
|
|
|
|
|
? ifp->ifindex : 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_IF_INDEXTONAME
|
|
|
|
|
char *
|
|
|
|
|
if_indextoname (unsigned int ifindex, char *name)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
if (!(ifp = if_lookup_by_index(ifindex)))
|
|
|
|
|
return NULL;
|
|
|
|
|
strncpy (name, ifp->name, IFNAMSIZ);
|
|
|
|
|
return ifp->name;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Interface looking up by interface's address. */
|
|
|
|
|
|
|
|
|
|
/* Interface's IPv4 address reverse lookup table. */
|
|
|
|
|
struct route_table *ifaddr_ipv4_table;
|
|
|
|
|
/* struct route_table *ifaddr_ipv6_table; */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
struct route_node *rn;
|
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
|
|
|
|
|
|
p.family = AF_INET;
|
|
|
|
|
p.prefixlen = IPV4_MAX_PREFIXLEN;
|
|
|
|
|
p.prefix = *ifaddr;
|
|
|
|
|
|
|
|
|
|
rn = route_node_get (ifaddr_ipv4_table, (struct prefix *) &p);
|
|
|
|
|
if (rn)
|
|
|
|
|
{
|
|
|
|
|
route_unlock_node (rn);
|
|
|
|
|
zlog_info ("ifaddr_ipv4_add(): address %s is already added",
|
|
|
|
|
inet_ntoa (*ifaddr));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
rn->info = ifp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp)
|
|
|
|
|
{
|
|
|
|
|
struct route_node *rn;
|
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
|
|
|
|
|
|
p.family = AF_INET;
|
|
|
|
|
p.prefixlen = IPV4_MAX_PREFIXLEN;
|
|
|
|
|
p.prefix = *ifaddr;
|
|
|
|
|
|
|
|
|
|
rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
|
|
|
|
|
if (! rn)
|
|
|
|
|
{
|
|
|
|
|
zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
|
|
|
|
|
inet_ntoa (*ifaddr));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
rn->info = NULL;
|
|
|
|
|
route_unlock_node (rn);
|
|
|
|
|
route_unlock_node (rn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Lookup interface by interface's IP address or interface index. */
|
|
|
|
|
struct interface *
|
|
|
|
|
ifaddr_ipv4_lookup (struct in_addr *addr, unsigned int ifindex)
|
|
|
|
|
{
|
|
|
|
|
struct prefix_ipv4 p;
|
|
|
|
|
struct route_node *rn;
|
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
|
|
if (addr)
|
|
|
|
|
{
|
|
|
|
|
p.family = AF_INET;
|
|
|
|
|
p.prefixlen = IPV4_MAX_PREFIXLEN;
|
|
|
|
|
p.prefix = *addr;
|
|
|
|
|
|
|
|
|
|
rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
|
|
|
|
|
if (! rn)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ifp = rn->info;
|
|
|
|
|
route_unlock_node (rn);
|
|
|
|
|
return ifp;
|
|
|
|
|
}
|
|
|
|
|
else
|
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
|
|
|
|
return if_lookup_by_index(ifindex);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize interface list. */
|
|
|
|
|
void
|
|
|
|
|
if_init ()
|
|
|
|
|
{
|
|
|
|
|
iflist = list_new ();
|
|
|
|
|
ifaddr_ipv4_table = route_table_init ();
|
|
|
|
|
|
2003-08-01 02:24:13 +02:00
|
|
|
|
if (iflist) {
|
|
|
|
|
iflist->cmp = (int (*)(void *, void *))if_cmp_func;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
return;
|
2003-08-01 02:24:13 +02:00
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
|
|
memset (&if_master, 0, sizeof if_master);
|
|
|
|
|
}
|