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. */ |
| 97 | int mtu; |
| 98 | |
| 99 | /* Hardware address. */ |
| 100 | #ifdef HAVE_SOCKADDR_DL |
| 101 | struct sockaddr_dl sdl; |
| 102 | #else |
| 103 | unsigned short hw_type; |
| 104 | u_char hw_addr[INTERFACE_HWADDR_MAX]; |
| 105 | int hw_addr_len; |
| 106 | #endif /* HAVE_SOCKADDR_DL */ |
| 107 | |
| 108 | /* interface bandwidth, kbits */ |
| 109 | unsigned int bandwidth; |
| 110 | |
| 111 | /* description of the interface. */ |
| 112 | char *desc; |
| 113 | |
| 114 | /* Distribute list. */ |
| 115 | void *distribute_in; |
| 116 | void *distribute_out; |
| 117 | |
| 118 | /* Connected address list. */ |
| 119 | list connected; |
| 120 | |
| 121 | /* Daemon specific interface data pointer. */ |
| 122 | void *info; |
| 123 | |
| 124 | /* Statistics fileds. */ |
| 125 | #ifdef HAVE_PROC_NET_DEV |
| 126 | struct if_stats stats; |
| 127 | #endif /* HAVE_PROC_NET_DEV */ |
| 128 | #ifdef HAVE_NET_RT_IFLIST |
| 129 | struct if_data stats; |
| 130 | #endif /* HAVE_NET_RT_IFLIST */ |
| 131 | }; |
| 132 | |
| 133 | /* Connected address structure. */ |
| 134 | struct connected |
| 135 | { |
| 136 | /* Attached interface. */ |
| 137 | struct interface *ifp; |
| 138 | |
| 139 | /* Flags for configuration. */ |
| 140 | u_char conf; |
| 141 | #define ZEBRA_IFC_REAL (1 << 0) |
| 142 | #define ZEBRA_IFC_CONFIGURED (1 << 1) |
| 143 | |
| 144 | /* Flags for connected address. */ |
| 145 | u_char flags; |
| 146 | #define ZEBRA_IFA_SECONDARY (1 << 0) |
| 147 | |
| 148 | /* Address of connected network. */ |
| 149 | struct prefix *address; |
| 150 | struct prefix *destination; |
| 151 | |
| 152 | /* Label for Linux 2.2.X and upper. */ |
| 153 | char *label; |
| 154 | }; |
| 155 | |
| 156 | /* Interface hook sort. */ |
| 157 | #define IF_NEW_HOOK 0 |
| 158 | #define IF_DELETE_HOOK 1 |
| 159 | |
| 160 | /* There are some interface flags which are only supported by some |
| 161 | operating system. */ |
| 162 | |
| 163 | #ifndef IFF_NOTRAILERS |
| 164 | #define IFF_NOTRAILERS 0x0 |
| 165 | #endif /* IFF_NOTRAILERS */ |
| 166 | #ifndef IFF_OACTIVE |
| 167 | #define IFF_OACTIVE 0x0 |
| 168 | #endif /* IFF_OACTIVE */ |
| 169 | #ifndef IFF_SIMPLEX |
| 170 | #define IFF_SIMPLEX 0x0 |
| 171 | #endif /* IFF_SIMPLEX */ |
| 172 | #ifndef IFF_LINK0 |
| 173 | #define IFF_LINK0 0x0 |
| 174 | #endif /* IFF_LINK0 */ |
| 175 | #ifndef IFF_LINK1 |
| 176 | #define IFF_LINK1 0x0 |
| 177 | #endif /* IFF_LINK1 */ |
| 178 | #ifndef IFF_LINK2 |
| 179 | #define IFF_LINK2 0x0 |
| 180 | #endif /* IFF_LINK2 */ |
| 181 | |
| 182 | /* Prototypes. */ |
| 183 | struct interface *if_new (void); |
| 184 | struct interface *if_create (void); |
| 185 | struct interface *if_lookup_by_index (unsigned int); |
| 186 | struct interface *if_lookup_by_name (char *); |
| 187 | struct interface *if_lookup_exact_address (struct in_addr); |
| 188 | struct interface *if_lookup_address (struct in_addr); |
| 189 | struct interface *if_get_by_name (char *); |
| 190 | void if_delete (struct interface *); |
| 191 | int if_is_up (struct interface *); |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 192 | int if_is_running (struct interface *); |
| 193 | int if_is_operative (struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 194 | int if_is_loopback (struct interface *); |
| 195 | int if_is_broadcast (struct interface *); |
| 196 | int if_is_pointopoint (struct interface *); |
| 197 | int if_is_multicast (struct interface *); |
| 198 | void if_add_hook (int, int (*)(struct interface *)); |
| 199 | void if_init (); |
| 200 | void if_dump_all (); |
| 201 | char *ifindex2ifname (unsigned int); |
| 202 | |
| 203 | /* Connected address functions. */ |
| 204 | struct connected *connected_new (); |
| 205 | void connected_free (struct connected *); |
| 206 | void connected_add (struct interface *, struct connected *); |
| 207 | struct connected *connected_delete_by_prefix (struct interface *, struct prefix *); |
paul | 727d104 | 2002-12-13 20:50:29 +0000 | [diff] [blame] | 208 | struct connected *connected_lookup_address (struct interface *, struct in_addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | int ifc_pointopoint (struct connected *); |
| 210 | |
| 211 | #ifndef HAVE_IF_NAMETOINDEX |
| 212 | unsigned int if_nametoindex (const char *); |
| 213 | #endif |
| 214 | #ifndef HAVE_IF_INDEXTONAME |
| 215 | char *if_indextoname (unsigned int, char *); |
| 216 | #endif |
| 217 | |
| 218 | /* Exported variables. */ |
| 219 | extern list iflist; |
| 220 | extern struct cmd_element interface_desc_cmd; |
| 221 | extern struct cmd_element no_interface_desc_cmd; |
| 222 | extern struct cmd_element interface_cmd; |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 223 | extern struct cmd_element no_interface_cmd; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | extern struct cmd_element interface_pseudo_cmd; |
| 225 | extern struct cmd_element no_interface_pseudo_cmd; |
| 226 | |
| 227 | #endif /* _ZEBRA_IF_H */ |