1 /* $OpenBSD: ripd.h,v 1.24 2016/09/02 14:07:52 benno Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Esben Norby <norby@openbsd.org> 5 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef RIPD_H 21 #define RIPD_H 22 23 #include <sys/queue.h> 24 #include <sys/socket.h> 25 #include <sys/tree.h> 26 #include <md5.h> 27 #include <net/if.h> 28 #include <netinet/in.h> 29 #include <event.h> 30 31 #include <imsg.h> 32 33 #define CONF_FILE "/etc/ripd.conf" 34 #define RIPD_SOCKET "/var/run/ripd.sock" 35 #define RIPD_USER "_ripd" 36 37 #define NBR_HASHSIZE 128 38 #define NBR_IDSELF 1 39 #define NBR_CNTSTART (NBR_IDSELF + 1) 40 41 #define ROUTE_TIMEOUT 180 42 #define ROUTE_GARBAGE 120 43 44 #define NBR_TIMEOUT 180 45 46 #define RT_BUF_SIZE 16384 47 #define MAX_RTSOCK_BUF 128 * 1024 48 49 #define RIPD_FLAG_NO_FIB_UPDATE 0x0001 50 51 #define F_RIPD_INSERTED 0x0001 52 #define F_KERNEL 0x0002 53 #define F_CONNECTED 0x0008 54 #define F_DOWN 0x0010 55 #define F_STATIC 0x0020 56 #define F_DYNAMIC 0x0040 57 #define F_REDISTRIBUTED 0x0100 58 #define F_REJECT 0x0200 59 #define F_BLACKHOLE 0x0400 60 61 #define REDISTRIBUTE_ON 0x01 62 63 #define OPT_SPLIT_HORIZON 0x01 64 #define OPT_SPLIT_POISONED 0x02 65 #define OPT_TRIGGERED_UPDATES 0x04 66 67 enum imsg_type { 68 IMSG_NONE, 69 IMSG_CTL_END, 70 IMSG_CTL_RELOAD, 71 IMSG_CTL_IFINFO, 72 IMSG_IFINFO, 73 IMSG_CTL_FIB_COUPLE, 74 IMSG_CTL_FIB_DECOUPLE, 75 IMSG_CTL_KROUTE, 76 IMSG_CTL_KROUTE_ADDR, 77 IMSG_CTL_SHOW_INTERFACE, 78 IMSG_CTL_SHOW_IFACE, 79 IMSG_CTL_SHOW_NBR, 80 IMSG_CTL_SHOW_RIB, 81 IMSG_CTL_LOG_VERBOSE, 82 IMSG_KROUTE_CHANGE, 83 IMSG_KROUTE_DELETE, 84 IMSG_NETWORK_ADD, 85 IMSG_NETWORK_DEL, 86 IMSG_ROUTE_FEED, 87 IMSG_RESPONSE_ADD, 88 IMSG_SEND_RESPONSE, 89 IMSG_FULL_RESPONSE, 90 IMSG_ROUTE_REQUEST, 91 IMSG_ROUTE_REQUEST_END, 92 IMSG_FULL_REQUEST, 93 IMSG_REQUEST_ADD, 94 IMSG_SEND_REQUEST, 95 IMSG_SEND_TRIGGERED_UPDATE, 96 IMSG_DEMOTE 97 }; 98 99 static const char * const log_procnames[] = { 100 "parent", 101 "ripe", 102 "rde" 103 }; 104 105 struct imsgev { 106 struct imsgbuf ibuf; 107 void (*handler)(int, short, void *); 108 struct event ev; 109 void *data; 110 short events; 111 }; 112 113 /* interface states */ 114 #define IF_STA_DOWN 0x01 115 #define IF_STA_ACTIVE (~IF_STA_DOWN) 116 #define IF_STA_ANY 0x7f 117 118 /* interface events */ 119 enum iface_event { 120 IF_EVT_NOTHING, 121 IF_EVT_UP, 122 IF_EVT_DOWN 123 }; 124 125 /* interface actions */ 126 enum iface_action { 127 IF_ACT_NOTHING, 128 IF_ACT_STRT, 129 IF_ACT_RST 130 }; 131 132 /* interface types */ 133 enum iface_type { 134 IF_TYPE_POINTOPOINT, 135 IF_TYPE_BROADCAST, 136 IF_TYPE_NBMA, 137 IF_TYPE_POINTOMULTIPOINT 138 }; 139 140 /* neighbor states */ 141 #define NBR_STA_DOWN 0x01 142 #define NBR_STA_REQ_RCVD 0x02 143 #define NBR_STA_ACTIVE (~NBR_STA_DOWN) 144 #define NBR_STA_ANY 0xff 145 146 struct auth_md { 147 TAILQ_ENTRY(auth_md) entry; 148 u_int32_t seq_modulator; 149 u_int8_t key[MD5_DIGEST_LENGTH]; 150 u_int8_t keyid; 151 }; 152 153 #define MAX_SIMPLE_AUTH_LEN 16 154 155 /* auth types */ 156 enum auth_type { 157 AUTH_NONE = 1, 158 AUTH_SIMPLE, 159 AUTH_CRYPT 160 }; 161 162 TAILQ_HEAD(auth_md_head, auth_md); 163 TAILQ_HEAD(packet_head, packet_entry); 164 165 struct iface { 166 LIST_ENTRY(iface) entry; 167 LIST_HEAD(, nbr) nbr_list; 168 LIST_HEAD(, nbr_failed) failed_nbr_list; 169 char name[IF_NAMESIZE]; 170 char demote_group[IFNAMSIZ]; 171 u_int8_t auth_key[MAX_SIMPLE_AUTH_LEN]; 172 struct in_addr addr; 173 struct in_addr dst; 174 struct in_addr mask; 175 struct packet_head rq_list; 176 struct packet_head rp_list; 177 struct auth_md_head auth_md_list; 178 179 u_int64_t baudrate; 180 time_t uptime; 181 u_int mtu; 182 int fd; /* XXX */ 183 int state; 184 u_short ifindex; 185 u_int16_t cost; 186 u_int16_t flags; 187 enum iface_type type; 188 enum auth_type auth_type; 189 u_int8_t linktype; 190 u_int8_t if_type; 191 u_int8_t passive; 192 u_int8_t linkstate; 193 u_int8_t auth_keyid; 194 }; 195 196 struct rip_route { 197 struct in_addr address; 198 struct in_addr mask; 199 struct in_addr nexthop; 200 int refcount; 201 u_short ifindex; 202 u_int8_t metric; 203 }; 204 205 struct packet_entry { 206 TAILQ_ENTRY(packet_entry) entry; 207 struct rip_route *rr; 208 }; 209 210 enum { 211 PROC_MAIN, 212 PROC_RIP_ENGINE, 213 PROC_RDE_ENGINE 214 } ripd_process; 215 216 #define REDIST_CONNECTED 0x01 217 #define REDIST_STATIC 0x02 218 #define REDIST_LABEL 0x04 219 #define REDIST_ADDR 0x08 220 #define REDIST_DEFAULT 0x10 221 #define REDIST_NO 0x20 222 223 struct redistribute { 224 SIMPLEQ_ENTRY(redistribute) entry; 225 struct in_addr addr; 226 struct in_addr mask; 227 u_int32_t metric; 228 u_int16_t label; 229 u_int16_t type; 230 }; 231 232 struct ripd_conf { 233 struct event ev; 234 struct event report_timer; 235 LIST_HEAD(, iface) iface_list; 236 SIMPLEQ_HEAD(, redistribute) redist_list; 237 238 u_int32_t opts; 239 #define RIPD_OPT_VERBOSE 0x00000001 240 #define RIPD_OPT_VERBOSE2 0x00000002 241 #define RIPD_OPT_NOACTION 0x00000004 242 #define RIPD_OPT_FORCE_DEMOTE 0x00000008 243 int flags; 244 int options; 245 int rip_socket; 246 int redistribute; 247 u_int rdomain; 248 char *csock; 249 }; 250 251 /* kroute */ 252 struct kroute { 253 struct in_addr prefix; 254 struct in_addr netmask; 255 struct in_addr nexthop; 256 u_int16_t flags; 257 u_int16_t rtlabel; 258 u_short ifindex; 259 u_int8_t metric; 260 u_int8_t priority; 261 }; 262 263 struct kif { 264 char ifname[IF_NAMESIZE]; 265 u_int64_t baudrate; 266 int flags; 267 int mtu; 268 u_short ifindex; 269 u_int8_t if_type; 270 u_int8_t link_state; 271 u_int8_t nh_reachable; /* for nexthop verification */ 272 }; 273 274 /* control data structures */ 275 struct ctl_iface { 276 char name[IF_NAMESIZE]; 277 struct in_addr addr; 278 struct in_addr mask; 279 280 time_t uptime; 281 time_t report_timer; 282 283 u_int64_t baudrate; 284 unsigned int ifindex; 285 int state; 286 int mtu; 287 288 u_int16_t flags; 289 u_int16_t metric; 290 enum iface_type type; 291 u_int8_t linkstate; 292 u_int8_t if_type; 293 u_int8_t passive; 294 }; 295 296 struct ctl_rt { 297 struct in_addr prefix; 298 struct in_addr netmask; 299 struct in_addr nexthop; 300 time_t uptime; 301 time_t expire; 302 u_int32_t metric; 303 u_int16_t flags; 304 }; 305 306 struct ctl_nbr { 307 char name[IF_NAMESIZE]; 308 struct in_addr id; 309 struct in_addr addr; 310 time_t dead_timer; 311 time_t uptime; 312 int nbr_state; 313 int iface_state; 314 }; 315 316 struct demote_msg { 317 char demote_group[IF_NAMESIZE]; 318 int level; 319 }; 320 321 int kif_init(void); 322 int kr_init(int, u_int); 323 int kr_change(struct kroute *); 324 int kr_delete(struct kroute *); 325 void kr_shutdown(void); 326 void kr_fib_couple(void); 327 void kr_fib_decouple(void); 328 void kr_dispatch_msg(int, short, void *); 329 void kr_show_route(struct imsg *); 330 void kr_ifinfo(char *, pid_t); 331 struct kif *kif_findname(char *); 332 333 in_addr_t prefixlen2mask(u_int8_t); 334 u_int8_t mask2prefixlen(in_addr_t); 335 336 /* ripd.c */ 337 void main_imsg_compose_ripe(int, pid_t, void *, u_int16_t); 338 void main_imsg_compose_rde(int, pid_t, void *, u_int16_t); 339 int rip_redistribute(struct kroute *); 340 void imsg_event_add(struct imsgev *); 341 int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, 342 pid_t, int, void *, u_int16_t); 343 344 /* parse.y */ 345 struct ripd_conf *parse_config(char *, int); 346 int cmdline_symset(char *); 347 348 /* carp.c */ 349 int carp_demote_init(char *, int); 350 void carp_demote_shutdown(void); 351 int carp_demote_get(char *); 352 int carp_demote_set(char *, int); 353 354 /* printconf.c */ 355 void print_config(struct ripd_conf *); 356 357 /* logmsg.c */ 358 const char *nbr_state_name(int); 359 const char *if_type_name(enum iface_type); 360 const char *if_auth_name(enum auth_type); 361 const char *if_state_name(int); 362 363 /* interface.c */ 364 struct iface *if_find_index(u_short); 365 366 /* name2id.c */ 367 u_int16_t rtlabel_name2id(const char *); 368 const char *rtlabel_id2name(u_int16_t); 369 void rtlabel_unref(u_int16_t); 370 371 #endif /* RIPD_H */ 372