mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-04 12:25:58 +00:00

2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating whether a peer address has been configured. Comment now shows the new interpretation of the destination addr: if ZEBRA_IFA_PEER is set, then it must contain the destination address, otherwise it may contain the broadcast address or be NULL. (CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete macros that were specific to IPv4 and not fully general. (CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag. (CONNECTED_PREFIX) New macro giving the prefix to insert into the RIB: if CONNECTED_PEER, then use the destination (peer) address, else use the address field. (CONNECTED_ID) New macro to come up with an identifying address for the struct connected. * if.c: (if_lookup_address, connected_lookup_address) Streamline logic with new CONNECTED_PREFIX macro. * prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros for better performance than the general prefix_copy function. * zclient.c: (zebra_interface_address_read) For non-null destination addresses, set prefixlen to equal the address prefixlen. This is needed to get the new CONNECTED_PREFIX macro to work properly. * connected.c: (connected_up_ipv4, connected_down_ipv4, connected_up_ipv6, connected_down_ipv6) Simplify logic using the new CONNECTED_PREFIX macro. (connected_add_ipv4) Set prefixlen in destination addresses (required by the CONNECTED_PREFIX macro). Use CONNECTED_PEER macro instead of testing for IFF_POINTOPOINT. Delete invalid warning message. Warn about cases where the ZEBRA_IFA_PEER is set but no destination address has been supplied (and turn off the flag). (connected_add_ipv6) Add new flags argument so callers may set the ZEBRA_IFA_PEER flag. If peer/broadcast address satisfies IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning. Set prefixlen in destination address so CONNECTED_PREFIX will work. * connected.h: (connected_add_ipv6) Add new flags argument so callers may set the ZEBRA_IFA_PEER flag. * interface.c: (connected_dump_vty) Use CONNECTED_PEER macro to decide whether the destination address is a peer or broadcast address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT). * if_ioctl.c: (if_getaddrs) Instead of setting a peer address only when the IFF_POINTOPOINT is set, we now accept a peer address whenever it is available and not the same as the local address. Otherwise (no peer address assigned), we check for a broadcast address (regardless of the IFF_BROADCAST flag). And must now pass a flags value of ZEBRA_IFA_PEER to connected_add_ipv4 when a peer address is assigned. The same new logic is used with the IPv6 code as well (and we pass the new flags argument to connected_add_ipv6). (if_get_addr) Do not bother to check IFF_POINTOPOINT: just issue the SIOCGIFDSTADDR ioctl and see if we get back a peer address not matching the local address (and set the ZEBRA_IFA_PEER in that case). If there's no peer address, try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set. * if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl without bothering to check the IFF_POINTOPOINT flag. And if no peer address was found, just try the SIOCGLIFBRDADDR ioctl without checking the IFF_BROADCAST flag. Call connected_add_ipv4 and connected_add_ipv6 with appropriate flags. * if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to connected_add_ipv6. * kernel_socket.c: (ifam_read) Must pass new flags argument to connected_add_ipv6. * rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2 to determine local and possible peer address (so there's no longer a test for IFF_POINTOPOINT). Set ZEBRA_IFA_PEER flag appropriately. Pass new flags argument to connected_add_ipv6. (netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast to determine whether the connected destination address is a broadcast address. * bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete) Simplify logic by using new CONNECTED_PREFIX macro. * ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix, ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX macro. * ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX macro, both options collapse into the same code. * ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new CONNECTED_ID macro. (ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX macro. * ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro instead of testing the IFF_POINTOPOINT flag. * ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro instead of testing with if_is_pointopoint. And add commented-out code to implement alternative (in my opinion) more elegant behavior that has no special-case treatment for PtP addresses. (ospf_network_run) Use new CONNECTED_ID macro to simplify logic. * rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID macro to simplify logic. (rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does not give a useful result if prefixlen is 32 (we require a peer address in such cases). * ripd.c: (rip_update_interface) Fix same bug as above.
312 lines
10 KiB
C
312 lines
10 KiB
C
/* 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
|
|
{
|
|
/* 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.
|
|
*/
|
|
char name[INTERFACE_NAMSIZ + 1];
|
|
|
|
/* Interface index (should be IFINDEX_INTERNAL for non-kernel or
|
|
deleted interfaces). */
|
|
unsigned int ifindex;
|
|
#define IFINDEX_INTERNAL 0
|
|
|
|
/* Zebra internal interface status */
|
|
u_char status;
|
|
#define ZEBRA_INTERFACE_ACTIVE (1 << 0)
|
|
#define ZEBRA_INTERFACE_SUB (1 << 1)
|
|
#define ZEBRA_INTERFACE_LINKDETECTION (1 << 2)
|
|
|
|
/* Interface flags. */
|
|
uint64_t flags;
|
|
|
|
/* Interface metric */
|
|
int metric;
|
|
|
|
/* Interface MTU. */
|
|
unsigned int mtu; /* IPv4 MTU */
|
|
unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */
|
|
|
|
/* 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. */
|
|
struct list *connected;
|
|
|
|
/* 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)
|
|
/*
|
|
The ZEBRA_IFC_REAL flag should be set if and only if this address
|
|
exists in the kernel.
|
|
The ZEBRA_IFC_CONFIGURED flag should be set if and only if this address
|
|
was configured by the user from inside quagga.
|
|
*/
|
|
|
|
/* Flags for connected address. */
|
|
u_char flags;
|
|
#define ZEBRA_IFA_SECONDARY (1 << 0)
|
|
#define ZEBRA_IFA_PEER (1 << 1)
|
|
/* N.B. the ZEBRA_IFA_PEER flag should be set if and only if
|
|
a peer address has been configured. If this flag is set,
|
|
the destination field must contain the peer address.
|
|
Otherwise, if this flag is not set, the destination address
|
|
will either contain a broadcast address or be NULL.
|
|
*/
|
|
|
|
/* Address of connected network. */
|
|
struct prefix *address;
|
|
|
|
/* Peer or Broadcast address, depending on whether ZEBRA_IFA_PEER is set.
|
|
Note: destination may be NULL if ZEBRA_IFA_PEER is not set. */
|
|
struct prefix *destination;
|
|
|
|
/* Label for Linux 2.2.X and upper. */
|
|
char *label;
|
|
};
|
|
|
|
/* Does the destination field contain a peer address? */
|
|
#define CONNECTED_PEER(C) CHECK_FLAG((C)->flags, ZEBRA_IFA_PEER)
|
|
|
|
/* Prefix to insert into the RIB */
|
|
#define CONNECTED_PREFIX(C) \
|
|
(CONNECTED_PEER(C) ? (C)->destination : (C)->address)
|
|
|
|
/* Identifying address. We guess that if there's a peer address, but the
|
|
local address is in the same prefix, then the local address may be unique. */
|
|
#define CONNECTED_ID(C) \
|
|
((CONNECTED_PEER(C) && !prefix_match((C)->destination, (C)->address)) ?\
|
|
(C)->destination : (C)->address)
|
|
|
|
/* 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 */
|
|
#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 */
|
|
|
|
/* Prototypes. */
|
|
extern int if_cmp_func (struct interface *, struct interface *);
|
|
extern struct interface *if_create (const char *name, int namelen);
|
|
extern struct interface *if_lookup_by_index (unsigned int);
|
|
extern struct interface *if_lookup_exact_address (struct in_addr);
|
|
extern struct interface *if_lookup_address (struct in_addr);
|
|
|
|
/* These 2 functions are to be used when the ifname argument is terminated
|
|
by a '\0' character: */
|
|
extern struct interface *if_lookup_by_name (const char *ifname);
|
|
extern struct interface *if_get_by_name (const char *ifname);
|
|
|
|
/* For these 2 functions, the namelen argument should be the precise length
|
|
of the ifname string (not counting any optional trailing '\0' character).
|
|
In most cases, strnlen should be used to calculate the namelen value. */
|
|
extern struct interface *if_lookup_by_name_len(const char *ifname,
|
|
size_t namelen);
|
|
extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
|
|
|
|
|
|
/* 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 *);
|
|
|
|
extern int if_is_up (struct interface *);
|
|
extern int if_is_running (struct interface *);
|
|
extern int if_is_operative (struct interface *);
|
|
extern int if_is_loopback (struct interface *);
|
|
extern int if_is_broadcast (struct interface *);
|
|
extern int if_is_pointopoint (struct interface *);
|
|
extern int if_is_multicast (struct interface *);
|
|
extern void if_add_hook (int, int (*)(struct interface *));
|
|
extern void if_init (void);
|
|
extern void if_dump_all (void);
|
|
extern const char *if_flag_dump(unsigned long);
|
|
|
|
/* Please use ifindex2ifname instead of if_indextoname where possible;
|
|
ifindex2ifname uses internal interface info, whereas if_indextoname must
|
|
make a system call. */
|
|
extern const 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);
|
|
|
|
/* Connected address functions. */
|
|
extern struct connected *connected_new (void);
|
|
extern void connected_free (struct connected *);
|
|
extern void connected_add (struct interface *, struct connected *);
|
|
extern struct connected *connected_add_by_prefix (struct interface *,
|
|
struct prefix *,
|
|
struct prefix *);
|
|
extern struct connected *connected_delete_by_prefix (struct interface *,
|
|
struct prefix *);
|
|
extern struct connected *connected_lookup_address (struct interface *,
|
|
struct in_addr);
|
|
|
|
#ifndef HAVE_IF_NAMETOINDEX
|
|
extern unsigned int if_nametoindex (const char *);
|
|
#endif
|
|
#ifndef HAVE_IF_INDEXTONAME
|
|
extern char *if_indextoname (unsigned int, char *);
|
|
#endif
|
|
|
|
/* Exported variables. */
|
|
extern struct list *iflist;
|
|
extern struct cmd_element interface_desc_cmd;
|
|
extern struct cmd_element no_interface_desc_cmd;
|
|
extern struct cmd_element interface_cmd;
|
|
extern struct cmd_element no_interface_cmd;
|
|
extern struct cmd_element interface_pseudo_cmd;
|
|
extern struct cmd_element no_interface_pseudo_cmd;
|
|
extern struct cmd_element show_address_cmd;
|
|
|
|
#endif /* _ZEBRA_IF_H */
|