1 /* $OpenBSD: ripd.h,v 1.26 2018/12/31 20:34:16 remi 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 (2 * 1024 * 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_int8_t fib_priority; 248 u_int rdomain; 249 char *csock; 250 }; 251 252 /* kroute */ 253 struct kroute { 254 struct in_addr prefix; 255 struct in_addr netmask; 256 struct in_addr nexthop; 257 u_int16_t flags; 258 u_int16_t rtlabel; 259 u_short ifindex; 260 u_int8_t metric; 261 u_int8_t priority; 262 }; 263 264 struct kif { 265 char ifname[IF_NAMESIZE]; 266 u_int64_t baudrate; 267 int flags; 268 int mtu; 269 u_short ifindex; 270 u_int8_t if_type; 271 u_int8_t link_state; 272 u_int8_t nh_reachable; /* for nexthop verification */ 273 }; 274 275 /* control data structures */ 276 struct ctl_iface { 277 char name[IF_NAMESIZE]; 278 struct in_addr addr; 279 struct in_addr mask; 280 281 time_t uptime; 282 time_t report_timer; 283 284 u_int64_t baudrate; 285 unsigned int ifindex; 286 int state; 287 int mtu; 288 289 u_int16_t flags; 290 u_int16_t metric; 291 enum iface_type type; 292 u_int8_t linkstate; 293 u_int8_t if_type; 294 u_int8_t passive; 295 }; 296 297 struct ctl_rt { 298 struct in_addr prefix; 299 struct in_addr netmask; 300 struct in_addr nexthop; 301 time_t uptime; 302 time_t expire; 303 u_int32_t metric; 304 u_int16_t flags; 305 }; 306 307 struct ctl_nbr { 308 char name[IF_NAMESIZE]; 309 struct in_addr id; 310 struct in_addr addr; 311 time_t dead_timer; 312 time_t uptime; 313 int nbr_state; 314 int iface_state; 315 }; 316 317 struct demote_msg { 318 char demote_group[IF_NAMESIZE]; 319 int level; 320 }; 321 322 int kif_init(void); 323 int kr_init(int, u_int, u_int8_t); 324 int kr_change(struct kroute *); 325 int kr_delete(struct kroute *); 326 void kr_shutdown(void); 327 void kr_fib_couple(void); 328 void kr_fib_decouple(void); 329 void kr_dispatch_msg(int, short, void *); 330 void kr_show_route(struct imsg *); 331 void kr_ifinfo(char *, pid_t); 332 struct kif *kif_findname(char *); 333 334 in_addr_t prefixlen2mask(u_int8_t); 335 u_int8_t mask2prefixlen(in_addr_t); 336 337 /* ripd.c */ 338 void main_imsg_compose_ripe(int, pid_t, void *, u_int16_t); 339 void main_imsg_compose_rde(int, pid_t, void *, u_int16_t); 340 int rip_redistribute(struct kroute *); 341 void imsg_event_add(struct imsgev *); 342 int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, 343 pid_t, int, void *, u_int16_t); 344 345 /* parse.y */ 346 struct ripd_conf *parse_config(char *, int); 347 int cmdline_symset(char *); 348 349 /* carp.c */ 350 int carp_demote_init(char *, int); 351 void carp_demote_shutdown(void); 352 int carp_demote_get(char *); 353 int carp_demote_set(char *, int); 354 355 /* printconf.c */ 356 void print_config(struct ripd_conf *); 357 358 /* logmsg.c */ 359 const char *nbr_state_name(int); 360 const char *if_type_name(enum iface_type); 361 const char *if_auth_name(enum auth_type); 362 const char *if_state_name(int); 363 364 /* interface.c */ 365 struct iface *if_find_index(u_short); 366 367 /* name2id.c */ 368 u_int16_t rtlabel_name2id(const char *); 369 const char *rtlabel_id2name(u_int16_t); 370 void rtlabel_unref(u_int16_t); 371 372 #endif /* RIPD_H */ 373