paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Interface related header. |
| 2 | Copyright (C) 1997, 98, 99 Kunihiro Ishiguro |
| 3 | |
| 4 | This file is part of GNU Zebra. |
| 5 | |
| 6 | GNU Zebra is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published |
| 8 | by the Free Software Foundation; either version 2, or (at your |
| 9 | option) any later version. |
| 10 | |
| 11 | GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Zebra; see the file COPYING. If not, write to the |
| 18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #ifndef _ZEBRA_IF_H |
| 22 | #define _ZEBRA_IF_H |
| 23 | |
| 24 | #include "linklist.h" |
| 25 | |
| 26 | /* |
| 27 | Interface name length. |
| 28 | |
| 29 | Linux define value in /usr/include/linux/if.h. |
| 30 | #define IFNAMSIZ 16 |
| 31 | |
| 32 | FreeBSD define value in /usr/include/net/if.h. |
| 33 | #define IFNAMSIZ 16 |
| 34 | */ |
| 35 | |
| 36 | #define INTERFACE_NAMSIZ 20 |
| 37 | #define INTERFACE_HWADDR_MAX 20 |
| 38 | |
| 39 | /* Internal If indexes start at 0xFFFFFFFF and go down to 1 greater |
| 40 | than this */ |
| 41 | #define IFINDEX_INTERNBASE 0x80000000 |
| 42 | |
| 43 | #ifdef HAVE_PROC_NET_DEV |
| 44 | struct if_stats |
| 45 | { |
| 46 | unsigned long rx_packets; /* total packets received */ |
| 47 | unsigned long tx_packets; /* total packets transmitted */ |
| 48 | unsigned long rx_bytes; /* total bytes received */ |
| 49 | unsigned long tx_bytes; /* total bytes transmitted */ |
| 50 | unsigned long rx_errors; /* bad packets received */ |
| 51 | unsigned long tx_errors; /* packet transmit problems */ |
| 52 | unsigned long rx_dropped; /* no space in linux buffers */ |
| 53 | unsigned long tx_dropped; /* no space available in linux */ |
| 54 | unsigned long rx_multicast; /* multicast packets received */ |
| 55 | unsigned long rx_compressed; |
| 56 | unsigned long tx_compressed; |
| 57 | unsigned long collisions; |
| 58 | |
| 59 | /* detailed rx_errors: */ |
| 60 | unsigned long rx_length_errors; |
| 61 | unsigned long rx_over_errors; /* receiver ring buff overflow */ |
| 62 | unsigned long rx_crc_errors; /* recved pkt with crc error */ |
| 63 | unsigned long rx_frame_errors; /* recv'd frame alignment error */ |
| 64 | unsigned long rx_fifo_errors; /* recv'r fifo overrun */ |
| 65 | unsigned long rx_missed_errors; /* receiver missed packet */ |
| 66 | /* detailed tx_errors */ |
| 67 | unsigned long tx_aborted_errors; |
| 68 | unsigned long tx_carrier_errors; |
| 69 | unsigned long tx_fifo_errors; |
| 70 | unsigned long tx_heartbeat_errors; |
| 71 | unsigned long tx_window_errors; |
| 72 | }; |
| 73 | #endif /* HAVE_PROC_NET_DEV */ |
| 74 | |
| 75 | /* Interface structure */ |
| 76 | struct interface |
| 77 | { |
| 78 | /* Interface name. */ |
| 79 | char name[INTERFACE_NAMSIZ + 1]; |
| 80 | |
| 81 | /* Interface index. */ |
| 82 | unsigned int ifindex; |
| 83 | |
| 84 | /* Zebra internal interface status */ |
| 85 | u_char status; |
| 86 | #define ZEBRA_INTERFACE_ACTIVE (1 << 0) |
| 87 | #define ZEBRA_INTERFACE_SUB (1 << 1) |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 88 | #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 89 | |
| 90 | /* Interface flags. */ |
| 91 | unsigned long flags; |
| 92 | |
| 93 | /* Interface metric */ |
| 94 | int metric; |
| 95 | |
| 96 | /* Interface MTU. */ |
paul | c9eca01 | 2004-10-11 11:28:44 +0000 | [diff] [blame] | 97 | unsigned int mtu; /* IPv4 MTU */ |
| 98 | unsigned int mtu6; /* IPv6 MTU - probably, but not neccessarily same as mtu */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 99 | |
| 100 | /* Hardware address. */ |
| 101 | #ifdef HAVE_SOCKADDR_DL |
| 102 | struct sockaddr_dl sdl; |
| 103 | #else |
| 104 | unsigned short hw_type; |
| 105 | u_char hw_addr[INTERFACE_HWADDR_MAX]; |
| 106 | int hw_addr_len; |
| 107 | #endif /* HAVE_SOCKADDR_DL */ |
| 108 | |
| 109 | /* interface bandwidth, kbits */ |
| 110 | unsigned int bandwidth; |
| 111 | |
| 112 | /* description of the interface. */ |
| 113 | char *desc; |
| 114 | |
| 115 | /* Distribute list. */ |
| 116 | void *distribute_in; |
| 117 | void *distribute_out; |
| 118 | |
| 119 | /* Connected address list. */ |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 120 | struct list *connected; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | |
| 122 | /* Daemon specific interface data pointer. */ |
| 123 | void *info; |
| 124 | |
| 125 | /* Statistics fileds. */ |
| 126 | #ifdef HAVE_PROC_NET_DEV |
| 127 | struct if_stats stats; |
| 128 | #endif /* HAVE_PROC_NET_DEV */ |
| 129 | #ifdef HAVE_NET_RT_IFLIST |
| 130 | struct if_data stats; |
| 131 | #endif /* HAVE_NET_RT_IFLIST */ |
| 132 | }; |
| 133 | |
| 134 | /* Connected address structure. */ |
| 135 | struct connected |
| 136 | { |
| 137 | /* Attached interface. */ |
| 138 | struct interface *ifp; |
| 139 | |
| 140 | /* Flags for configuration. */ |
| 141 | u_char conf; |
| 142 | #define ZEBRA_IFC_REAL (1 << 0) |
| 143 | #define ZEBRA_IFC_CONFIGURED (1 << 1) |
| 144 | |
| 145 | /* Flags for connected address. */ |
| 146 | u_char flags; |
| 147 | #define ZEBRA_IFA_SECONDARY (1 << 0) |
| 148 | |
| 149 | /* Address of connected network. */ |
| 150 | struct prefix *address; |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 151 | struct prefix *destination; /* broadcast or peer address; may be NULL */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | |
| 153 | /* Label for Linux 2.2.X and upper. */ |
| 154 | char *label; |
| 155 | }; |
| 156 | |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 157 | /* Given an IPV4 struct connected, this macro determines whether a /32 |
| 158 | peer address has been supplied (i.e. there is no subnet assigned) */ |
| 159 | #define CONNECTED_DEST_HOST(C) \ |
| 160 | ((C)->destination && ((C)->address->prefixlen == IPV4_MAX_PREFIXLEN)) |
| 161 | |
| 162 | /* Given an IPV4 struct connected, this macro determins whether it is |
| 163 | a point-to-point link with a /32 peer address (i.e. there |
| 164 | is no dedicated subnet for the PtP link) */ |
| 165 | #define CONNECTED_POINTOPOINT_HOST(C) \ |
| 166 | (((C)->ifp->flags & IFF_POINTOPOINT) && CONNECTED_DEST_HOST(C)) |
| 167 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | /* Interface hook sort. */ |
| 169 | #define IF_NEW_HOOK 0 |
| 170 | #define IF_DELETE_HOOK 1 |
| 171 | |
| 172 | /* There are some interface flags which are only supported by some |
| 173 | operating system. */ |
| 174 | |
| 175 | #ifndef IFF_NOTRAILERS |
| 176 | #define IFF_NOTRAILERS 0x0 |
| 177 | #endif /* IFF_NOTRAILERS */ |
| 178 | #ifndef IFF_OACTIVE |
| 179 | #define IFF_OACTIVE 0x0 |
| 180 | #endif /* IFF_OACTIVE */ |
| 181 | #ifndef IFF_SIMPLEX |
| 182 | #define IFF_SIMPLEX 0x0 |
| 183 | #endif /* IFF_SIMPLEX */ |
| 184 | #ifndef IFF_LINK0 |
| 185 | #define IFF_LINK0 0x0 |
| 186 | #endif /* IFF_LINK0 */ |
| 187 | #ifndef IFF_LINK1 |
| 188 | #define IFF_LINK1 0x0 |
| 189 | #endif /* IFF_LINK1 */ |
| 190 | #ifndef IFF_LINK2 |
| 191 | #define IFF_LINK2 0x0 |
| 192 | #endif /* IFF_LINK2 */ |
| 193 | |
| 194 | /* Prototypes. */ |
paul | 106d2fd | 2003-08-01 00:24:13 +0000 | [diff] [blame] | 195 | int if_cmp_func (struct interface *, struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 196 | struct interface *if_new (void); |
paul | 9035efa | 2004-10-10 11:56:56 +0000 | [diff] [blame] | 197 | struct interface *if_create (const char *name, int namelen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 198 | struct interface *if_lookup_by_index (unsigned int); |
paul | 9035efa | 2004-10-10 11:56:56 +0000 | [diff] [blame] | 199 | struct interface *if_lookup_by_name (const char *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 200 | struct interface *if_lookup_exact_address (struct in_addr); |
| 201 | struct interface *if_lookup_address (struct in_addr); |
paul | 9035efa | 2004-10-10 11:56:56 +0000 | [diff] [blame] | 202 | struct interface *if_get_by_name (const char *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 203 | void if_delete (struct interface *); |
| 204 | int if_is_up (struct interface *); |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 205 | int if_is_running (struct interface *); |
| 206 | int if_is_operative (struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | int if_is_loopback (struct interface *); |
| 208 | int if_is_broadcast (struct interface *); |
| 209 | int if_is_pointopoint (struct interface *); |
| 210 | int if_is_multicast (struct interface *); |
| 211 | void if_add_hook (int, int (*)(struct interface *)); |
| 212 | void if_init (); |
| 213 | void if_dump_all (); |
| 214 | char *ifindex2ifname (unsigned int); |
| 215 | |
| 216 | /* Connected address functions. */ |
| 217 | struct connected *connected_new (); |
| 218 | void connected_free (struct connected *); |
| 219 | void connected_add (struct interface *, struct connected *); |
paul | 4a7aac1 | 2004-05-08 05:00:31 +0000 | [diff] [blame] | 220 | struct connected *connected_add_by_prefix (struct interface *, |
| 221 | struct prefix *, |
| 222 | struct prefix *); |
| 223 | struct connected *connected_delete_by_prefix (struct interface *, |
| 224 | struct prefix *); |
| 225 | struct connected *connected_lookup_address (struct interface *, |
| 226 | struct in_addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 227 | |
| 228 | #ifndef HAVE_IF_NAMETOINDEX |
| 229 | unsigned int if_nametoindex (const char *); |
| 230 | #endif |
| 231 | #ifndef HAVE_IF_INDEXTONAME |
| 232 | char *if_indextoname (unsigned int, char *); |
| 233 | #endif |
| 234 | |
| 235 | /* Exported variables. */ |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 236 | extern struct list *iflist; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 237 | extern struct cmd_element interface_desc_cmd; |
| 238 | extern struct cmd_element no_interface_desc_cmd; |
| 239 | extern struct cmd_element interface_cmd; |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 240 | extern struct cmd_element no_interface_cmd; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 241 | extern struct cmd_element interface_pseudo_cmd; |
| 242 | extern struct cmd_element no_interface_pseudo_cmd; |
| 243 | |
| 244 | #endif /* _ZEBRA_IF_H */ |