2002-12-13 21:15:29 +01:00
|
|
|
/* Interface related header.
|
|
|
|
Copyright (C) 1997, 98, 99 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. */
|
|
|
|
|
|
|
|
#ifndef _ZEBRA_IF_H
|
|
|
|
#define _ZEBRA_IF_H
|
|
|
|
|
|
|
|
#include "linklist.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
Interface name length.
|
|
|
|
|
|
|
|
Linux define value in /usr/include/linux/if.h.
|
|
|
|
#define IFNAMSIZ 16
|
|
|
|
|
|
|
|
FreeBSD define value in /usr/include/net/if.h.
|
|
|
|
#define IFNAMSIZ 16
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define INTERFACE_NAMSIZ 20
|
|
|
|
#define INTERFACE_HWADDR_MAX 20
|
|
|
|
|
|
|
|
#ifdef HAVE_PROC_NET_DEV
|
|
|
|
struct if_stats
|
|
|
|
{
|
|
|
|
unsigned long rx_packets; /* total packets received */
|
|
|
|
unsigned long tx_packets; /* total packets transmitted */
|
|
|
|
unsigned long rx_bytes; /* total bytes received */
|
|
|
|
unsigned long tx_bytes; /* total bytes transmitted */
|
|
|
|
unsigned long rx_errors; /* bad packets received */
|
|
|
|
unsigned long tx_errors; /* packet transmit problems */
|
|
|
|
unsigned long rx_dropped; /* no space in linux buffers */
|
|
|
|
unsigned long tx_dropped; /* no space available in linux */
|
|
|
|
unsigned long rx_multicast; /* multicast packets received */
|
|
|
|
unsigned long rx_compressed;
|
|
|
|
unsigned long tx_compressed;
|
|
|
|
unsigned long collisions;
|
|
|
|
|
|
|
|
/* detailed rx_errors: */
|
|
|
|
unsigned long rx_length_errors;
|
|
|
|
unsigned long rx_over_errors; /* receiver ring buff overflow */
|
|
|
|
unsigned long rx_crc_errors; /* recved pkt with crc error */
|
|
|
|
unsigned long rx_frame_errors; /* recv'd frame alignment error */
|
|
|
|
unsigned long rx_fifo_errors; /* recv'r fifo overrun */
|
|
|
|
unsigned long rx_missed_errors; /* receiver missed packet */
|
|
|
|
/* detailed tx_errors */
|
|
|
|
unsigned long tx_aborted_errors;
|
|
|
|
unsigned long tx_carrier_errors;
|
|
|
|
unsigned long tx_fifo_errors;
|
|
|
|
unsigned long tx_heartbeat_errors;
|
|
|
|
unsigned long tx_window_errors;
|
|
|
|
};
|
|
|
|
#endif /* HAVE_PROC_NET_DEV */
|
|
|
|
|
|
|
|
/* Interface structure */
|
|
|
|
struct interface
|
|
|
|
{
|
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
|
|
|
/* Interface name. This should probably never be changed after the
|
|
|
|
interface is created, because the configuration info for this interface
|
|
|
|
is associated with this structure. For that reason, the interface
|
|
|
|
should also never be deleted (to avoid losing configuration info).
|
|
|
|
To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
|
|
|
|
interface does not exist in the kernel.
|
|
|
|
*/
|
2002-12-13 21:15:29 +01:00
|
|
|
char name[INTERFACE_NAMSIZ + 1];
|
|
|
|
|
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
|
|
|
/* Interface index (should be IFINDEX_INTERNAL for non-kernel or
|
|
|
|
deleted interfaces). */
|
2002-12-13 21:15:29 +01:00
|
|
|
unsigned int ifindex;
|
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
|
|
|
#define IFINDEX_INTERNAL 0
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Zebra internal interface status */
|
|
|
|
u_char status;
|
|
|
|
#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
|
|
|
|
#define ZEBRA_INTERFACE_SUB (1 << 1)
|
2002-12-13 22:03:13 +01:00
|
|
|
#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Interface flags. */
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* Interface metric */
|
|
|
|
int metric;
|
|
|
|
|
|
|
|
/* Interface MTU. */
|
2004-10-11 13:28:44 +02:00
|
|
|
unsigned int mtu; /* IPv4 MTU */
|
|
|
|
unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Hardware address. */
|
|
|
|
#ifdef HAVE_SOCKADDR_DL
|
|
|
|
struct sockaddr_dl sdl;
|
|
|
|
#else
|
|
|
|
unsigned short hw_type;
|
|
|
|
u_char hw_addr[INTERFACE_HWADDR_MAX];
|
|
|
|
int hw_addr_len;
|
|
|
|
#endif /* HAVE_SOCKADDR_DL */
|
|
|
|
|
|
|
|
/* interface bandwidth, kbits */
|
|
|
|
unsigned int bandwidth;
|
|
|
|
|
|
|
|
/* description of the interface. */
|
|
|
|
char *desc;
|
|
|
|
|
|
|
|
/* Distribute list. */
|
|
|
|
void *distribute_in;
|
|
|
|
void *distribute_out;
|
|
|
|
|
|
|
|
/* Connected address list. */
|
2004-09-23 21:18:23 +02:00
|
|
|
struct list *connected;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Daemon specific interface data pointer. */
|
|
|
|
void *info;
|
|
|
|
|
|
|
|
/* Statistics fileds. */
|
|
|
|
#ifdef HAVE_PROC_NET_DEV
|
|
|
|
struct if_stats stats;
|
|
|
|
#endif /* HAVE_PROC_NET_DEV */
|
|
|
|
#ifdef HAVE_NET_RT_IFLIST
|
|
|
|
struct if_data stats;
|
|
|
|
#endif /* HAVE_NET_RT_IFLIST */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Connected address structure. */
|
|
|
|
struct connected
|
|
|
|
{
|
|
|
|
/* Attached interface. */
|
|
|
|
struct interface *ifp;
|
|
|
|
|
|
|
|
/* Flags for configuration. */
|
|
|
|
u_char conf;
|
|
|
|
#define ZEBRA_IFC_REAL (1 << 0)
|
|
|
|
#define ZEBRA_IFC_CONFIGURED (1 << 1)
|
|
|
|
|
|
|
|
/* Flags for connected address. */
|
|
|
|
u_char flags;
|
|
|
|
#define ZEBRA_IFA_SECONDARY (1 << 0)
|
|
|
|
|
|
|
|
/* Address of connected network. */
|
|
|
|
struct prefix *address;
|
2004-10-19 21:44:43 +02:00
|
|
|
struct prefix *destination; /* broadcast or peer address; may be NULL */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Label for Linux 2.2.X and upper. */
|
|
|
|
char *label;
|
|
|
|
};
|
|
|
|
|
2004-10-19 21:44:43 +02:00
|
|
|
/* Given an IPV4 struct connected, this macro determines whether a /32
|
|
|
|
peer address has been supplied (i.e. there is no subnet assigned) */
|
|
|
|
#define CONNECTED_DEST_HOST(C) \
|
|
|
|
((C)->destination && ((C)->address->prefixlen == IPV4_MAX_PREFIXLEN))
|
|
|
|
|
|
|
|
/* Given an IPV4 struct connected, this macro determins whether it is
|
|
|
|
a point-to-point link with a /32 peer address (i.e. there
|
|
|
|
is no dedicated subnet for the PtP link) */
|
|
|
|
#define CONNECTED_POINTOPOINT_HOST(C) \
|
|
|
|
(((C)->ifp->flags & IFF_POINTOPOINT) && CONNECTED_DEST_HOST(C))
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Interface hook sort. */
|
|
|
|
#define IF_NEW_HOOK 0
|
|
|
|
#define IF_DELETE_HOOK 1
|
|
|
|
|
|
|
|
/* There are some interface flags which are only supported by some
|
|
|
|
operating system. */
|
|
|
|
|
|
|
|
#ifndef IFF_NOTRAILERS
|
|
|
|
#define IFF_NOTRAILERS 0x0
|
|
|
|
#endif /* IFF_NOTRAILERS */
|
|
|
|
#ifndef IFF_OACTIVE
|
|
|
|
#define IFF_OACTIVE 0x0
|
|
|
|
#endif /* IFF_OACTIVE */
|
|
|
|
#ifndef IFF_SIMPLEX
|
|
|
|
#define IFF_SIMPLEX 0x0
|
|
|
|
#endif /* IFF_SIMPLEX */
|
|
|
|
#ifndef IFF_LINK0
|
|
|
|
#define IFF_LINK0 0x0
|
|
|
|
#endif /* IFF_LINK0 */
|
|
|
|
#ifndef IFF_LINK1
|
|
|
|
#define IFF_LINK1 0x0
|
|
|
|
#endif /* IFF_LINK1 */
|
|
|
|
#ifndef IFF_LINK2
|
|
|
|
#define IFF_LINK2 0x0
|
|
|
|
#endif /* IFF_LINK2 */
|
2004-12-21 23:34:58 +01:00
|
|
|
#ifndef IFF_NOXMIT
|
|
|
|
#define IFF_NOXMIT 0x0
|
|
|
|
#endif /* IFF_NOXMIT */
|
|
|
|
#ifndef IFF_NORTEXCH
|
|
|
|
#define IFF_NORTEXCH 0x0
|
|
|
|
#endif /* IFF_NORTEXCH */
|
|
|
|
#ifndef IFF_IPV4
|
|
|
|
#define IFF_IPV4 0x0
|
|
|
|
#endif /* IFF_IPV4 */
|
|
|
|
#ifndef IFF_IPV6
|
|
|
|
#define IFF_IPV6 0x0
|
|
|
|
#endif /* IFF_IPV6 */
|
|
|
|
#ifndef IFF_VIRTUAL
|
|
|
|
#define IFF_VIRTUAL 0x0
|
|
|
|
#endif /* IFF_VIRTUAL */
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Prototypes. */
|
2003-08-01 02:24:13 +02:00
|
|
|
int if_cmp_func (struct interface *, 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
|
|
|
struct interface *if_create (const char *name, int namelen);
|
2002-12-13 21:15:29 +01:00
|
|
|
struct interface *if_lookup_by_index (unsigned int);
|
|
|
|
struct interface *if_lookup_exact_address (struct in_addr);
|
|
|
|
struct interface *if_lookup_address (struct in_addr);
|
2005-04-03 00:50:38 +02:00
|
|
|
|
|
|
|
/* Currently, the code assumes that the interface name arguments to these
|
|
|
|
functions have length <= INTERFACE_NAMSIZ, and they must be NUL-terminated
|
|
|
|
if they are shorter than INTERFACE_NAMSIZ. After code cleanup, the
|
|
|
|
implementation will be changed to require the arguments to these functions
|
|
|
|
to terminate with a NUL character (no length limitation). */
|
|
|
|
struct interface *if_lookup_by_name (const char *);
|
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
|
|
|
struct interface *if_get_by_name (const char *);
|
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
|
|
|
|
2005-04-03 00:50:38 +02:00
|
|
|
/* For these 2 functions, the 2nd argument should be the precise length
|
|
|
|
of the interface name (not counting a trailing NUL which may or may
|
|
|
|
not be present). */
|
|
|
|
extern struct interface *if_lookup_by_name_len(const char *name,
|
|
|
|
size_t namelen);
|
|
|
|
extern struct interface *if_get_by_name_len(const char *name, size_t 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
|
|
|
/* Delete the interface, but do not free the structure, and leave it in the
|
|
|
|
interface list. It is often advisable to leave the pseudo interface
|
|
|
|
structure because there may be configuration information attached. */
|
|
|
|
extern void if_delete_retain (struct interface *);
|
|
|
|
|
|
|
|
/* Delete and free the interface structure: calls if_delete_retain and then
|
|
|
|
deletes it from the interface list and frees the structure. */
|
|
|
|
extern void if_delete (struct interface *);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
int if_is_up (struct interface *);
|
2002-12-13 22:03:13 +01:00
|
|
|
int if_is_running (struct interface *);
|
|
|
|
int if_is_operative (struct interface *);
|
2002-12-13 21:15:29 +01:00
|
|
|
int if_is_loopback (struct interface *);
|
|
|
|
int if_is_broadcast (struct interface *);
|
|
|
|
int if_is_pointopoint (struct interface *);
|
|
|
|
int if_is_multicast (struct interface *);
|
|
|
|
void if_add_hook (int, int (*)(struct interface *));
|
|
|
|
void if_init ();
|
|
|
|
void if_dump_all ();
|
2005-02-02 19:38:48 +01:00
|
|
|
extern const char *if_flag_dump(unsigned long);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
Fix problems when netlink interfaces are renamed (same ifindex used
for a new interface). Start cleaning up some problems with the way
interface names are handled.
* interface.c: (if_new_intern_ifindex) Remove obsolete function.
(if_delete_update) After distributing the interface deletion message,
set ifp->ifindex to IFINDEX_INTERNAL.
(if_dump_vty) Detect pseudo interface by checking if ifp->ifindex is
IFINDEX_INTERNAL.
(zebra_interface) Check return code from interface_cmd.func.
Do not set internal ifindex values to if_new_intern_ifindex(),
since we now use IFINDEX_INTERNAL for all pseudo interfaces.
* kernel_socket.c: (ifm_read) Fix code and comments to reflect that
all internal interfaces now have ifp->ifindex set to IFINDEX_INTERNAL.
* rt_netlink.c: (set_ifindex) New function used to update ifp->ifindex.
Detects interface rename events by checking if that ifindex is already
being used. If it is, delete the old interface before assigning
the ifindex to the new interface.
(netlink_interface, netlink_link_change) Call set_ifindex to update
the ifindex.
* if.h: Remove define for IFINDEX_INTERNBASE and add define
IFINDEX_INTERNAL 0, since all internal (i.e. non-kernel) pseudo-
interfaces should have ifindex set to 0.
(if_new) Remove function.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(ifname2ifindex) New function.
* if.c: (if_new) Remove function (absorb into if_create).
(if_create) Replace function if_new with call to calloc.
Set ifp->ifindex to IFINDEX_INTERNAL. Fix off-by-one error
in assert to check length of interface name. Add error message
if interface with this name already exists.
(if_delete_retain) New function to delete an interface without
removing from iflist and freeing the structure.
(if_delete) Implement with help of if_delete_retain.
(ifindex2ifname) Reimplement using if_lookup_by_index.
(ifname2ifindex) New function to complement ifindex2ifname.
(interface) The interface command should check the name length
and fail with a warning message if it is too long.
(no_interface) Fix spelling in warning message.
(if_nametoindex) Reimplement using if_lookup_by_name.
(if_indextoname, ifaddr_ipv4_lookup) Reimplement using
if_lookup_by_index.
* bgp_zebra.c: (bgp_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
* isis_zebra.c: (isis_zebra_if_del) Call if_delete_retain instead
of if_delete, since it is generally not safe to remove interface
structures. After deleting, set ifp->ifindex to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Tighten up code.
* ospf6_zebra.c: (ospf6_zebra_if_del) Previously, this whole function
was commented out. But this is not safe: we should at least update
the ifindex when the interface is deleted. So the new version
updates the interface status and sets ifp->ifindex to
IFINDEX_INTERNAL.
(ospf6_zebra_route_update) Use if_indextoname properly.
* ospf_vty.c: (show_ip_ospf_interface_sub) Show ifindex and interface
flags to help with debugging.
* ospf_zebra.c: (ospf_interface_delete) After deleting, set ifp->ifindex
to IFINDEX_INTERNAL.
(zebra_interface_if_lookup) Make function static. Tighten up code.
* rip_interface.c: (rip_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
* ripng_interface.c: (ripng_interface_delete) After deleting, set
ifp->ifindex to IFINDEX_INTERNAL.
2005-04-02 20:38:43 +02:00
|
|
|
/* Please use ifindex2ifname instead of if_indextoname where possible;
|
|
|
|
ifindex2ifname uses internal interface info, whereas if_indextoname must
|
|
|
|
make a system call. */
|
|
|
|
extern char *ifindex2ifname (unsigned int);
|
|
|
|
|
|
|
|
/* Please use ifname2ifindex instead of if_nametoindex where possible;
|
|
|
|
ifname2ifindex uses internal interface info, whereas if_nametoindex must
|
|
|
|
make a system call. */
|
|
|
|
extern unsigned int ifname2ifindex(const char *ifname);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Connected address functions. */
|
|
|
|
struct connected *connected_new ();
|
|
|
|
void connected_free (struct connected *);
|
|
|
|
void connected_add (struct interface *, struct connected *);
|
2004-05-08 07:00:31 +02:00
|
|
|
struct connected *connected_add_by_prefix (struct interface *,
|
|
|
|
struct prefix *,
|
|
|
|
struct prefix *);
|
|
|
|
struct connected *connected_delete_by_prefix (struct interface *,
|
|
|
|
struct prefix *);
|
|
|
|
struct connected *connected_lookup_address (struct interface *,
|
|
|
|
struct in_addr);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
#ifndef HAVE_IF_NAMETOINDEX
|
|
|
|
unsigned int if_nametoindex (const char *);
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_IF_INDEXTONAME
|
|
|
|
char *if_indextoname (unsigned int, char *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Exported variables. */
|
2004-09-23 21:18:23 +02:00
|
|
|
extern struct list *iflist;
|
2002-12-13 21:15:29 +01:00
|
|
|
extern struct cmd_element interface_desc_cmd;
|
|
|
|
extern struct cmd_element no_interface_desc_cmd;
|
|
|
|
extern struct cmd_element interface_cmd;
|
2003-05-23 11:25:20 +02:00
|
|
|
extern struct cmd_element no_interface_cmd;
|
2002-12-13 21:15:29 +01:00
|
|
|
extern struct cmd_element interface_pseudo_cmd;
|
|
|
|
extern struct cmd_element no_interface_pseudo_cmd;
|
|
|
|
|
|
|
|
#endif /* _ZEBRA_IF_H */
|