1 /* $OpenBSD: ripd.h,v 1.29 2024/10/22 22:50:49 jsg 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 READ_BUF_SIZE 65535 47 #define RT_BUF_SIZE 16384 48 #define MAX_RTSOCK_BUF (2 * 1024 * 1024) 49 50 #define RIPD_FLAG_NO_FIB_UPDATE 0x0001 51 52 #define F_RIPD_INSERTED 0x0001 53 #define F_KERNEL 0x0002 54 #define F_CONNECTED 0x0008 55 #define F_DOWN 0x0010 56 #define F_STATIC 0x0020 57 #define F_DYNAMIC 0x0040 58 #define F_REDISTRIBUTED 0x0100 59 #define F_REJECT 0x0200 60 #define F_BLACKHOLE 0x0400 61 62 #define REDISTRIBUTE_ON 0x01 63 64 #define OPT_SPLIT_HORIZON 0x01 65 #define OPT_SPLIT_POISONED 0x02 66 #define OPT_TRIGGERED_UPDATES 0x04 67 68 enum imsg_type { 69 IMSG_NONE, 70 IMSG_CTL_END, 71 IMSG_CTL_RELOAD, 72 IMSG_CTL_IFINFO, 73 IMSG_IFINFO, 74 IMSG_CTL_FIB_COUPLE, 75 IMSG_CTL_FIB_DECOUPLE, 76 IMSG_CTL_KROUTE, 77 IMSG_CTL_KROUTE_ADDR, 78 IMSG_CTL_SHOW_INTERFACE, 79 IMSG_CTL_SHOW_IFACE, 80 IMSG_CTL_SHOW_NBR, 81 IMSG_CTL_SHOW_RIB, 82 IMSG_CTL_LOG_VERBOSE, 83 IMSG_KROUTE_CHANGE, 84 IMSG_KROUTE_DELETE, 85 IMSG_NETWORK_ADD, 86 IMSG_NETWORK_DEL, 87 IMSG_ROUTE_FEED, 88 IMSG_RESPONSE_ADD, 89 IMSG_SEND_RESPONSE, 90 IMSG_FULL_RESPONSE, 91 IMSG_ROUTE_REQUEST, 92 IMSG_ROUTE_REQUEST_END, 93 IMSG_FULL_REQUEST, 94 IMSG_REQUEST_ADD, 95 IMSG_SEND_REQUEST, 96 IMSG_SEND_TRIGGERED_UPDATE, 97 IMSG_DEMOTE 98 }; 99 100 struct imsgev { 101 struct imsgbuf ibuf; 102 void (*handler)(int, short, void *); 103 struct event ev; 104 void *data; 105 short events; 106 }; 107 108 /* interface states */ 109 #define IF_STA_DOWN 0x01 110 #define IF_STA_ACTIVE (~IF_STA_DOWN) 111 #define IF_STA_ANY 0x7f 112 113 /* interface events */ 114 enum iface_event { 115 IF_EVT_NOTHING, 116 IF_EVT_UP, 117 IF_EVT_DOWN 118 }; 119 120 /* interface actions */ 121 enum iface_action { 122 IF_ACT_NOTHING, 123 IF_ACT_STRT, 124 IF_ACT_RST 125 }; 126 127 /* interface types */ 128 enum iface_type { 129 IF_TYPE_POINTOPOINT, 130 IF_TYPE_BROADCAST, 131 IF_TYPE_NBMA, 132 IF_TYPE_POINTOMULTIPOINT 133 }; 134 135 /* neighbor states */ 136 #define NBR_STA_DOWN 0x01 137 #define NBR_STA_REQ_RCVD 0x02 138 #define NBR_STA_ACTIVE (~NBR_STA_DOWN) 139 #define NBR_STA_ANY 0xff 140 141 struct auth_md { 142 TAILQ_ENTRY(auth_md) entry; 143 u_int32_t seq_modulator; 144 u_int8_t key[MD5_DIGEST_LENGTH]; 145 u_int8_t keyid; 146 }; 147 148 #define MAX_SIMPLE_AUTH_LEN 16 149 150 /* auth types */ 151 enum auth_type { 152 AUTH_NONE = 1, 153 AUTH_SIMPLE, 154 AUTH_CRYPT 155 }; 156 157 TAILQ_HEAD(auth_md_head, auth_md); 158 TAILQ_HEAD(packet_head, packet_entry); 159 160 struct iface { 161 LIST_ENTRY(iface) entry; 162 LIST_HEAD(, nbr) nbr_list; 163 LIST_HEAD(, nbr_failed) failed_nbr_list; 164 char name[IF_NAMESIZE]; 165 char demote_group[IFNAMSIZ]; 166 u_int8_t auth_key[MAX_SIMPLE_AUTH_LEN]; 167 struct in_addr addr; 168 struct in_addr dst; 169 struct in_addr mask; 170 struct packet_head rq_list; 171 struct packet_head rp_list; 172 struct auth_md_head auth_md_list; 173 174 u_int64_t baudrate; 175 time_t uptime; 176 u_int mtu; 177 int fd; /* XXX */ 178 int state; 179 u_short ifindex; 180 u_int16_t cost; 181 u_int16_t flags; 182 enum iface_type type; 183 enum auth_type auth_type; 184 u_int8_t linktype; 185 u_int8_t if_type; 186 u_int8_t passive; 187 u_int8_t linkstate; 188 u_int8_t auth_keyid; 189 }; 190 191 struct rip_route { 192 struct in_addr address; 193 struct in_addr mask; 194 struct in_addr nexthop; 195 int refcount; 196 u_short ifindex; 197 u_int8_t metric; 198 }; 199 200 struct packet_entry { 201 TAILQ_ENTRY(packet_entry) entry; 202 struct rip_route *rr; 203 }; 204 205 #define REDIST_CONNECTED 0x01 206 #define REDIST_STATIC 0x02 207 #define REDIST_LABEL 0x04 208 #define REDIST_ADDR 0x08 209 #define REDIST_DEFAULT 0x10 210 #define REDIST_NO 0x20 211 212 struct redistribute { 213 SIMPLEQ_ENTRY(redistribute) entry; 214 struct in_addr addr; 215 struct in_addr mask; 216 u_int32_t metric; 217 u_int16_t label; 218 u_int16_t type; 219 }; 220 221 struct ripd_conf { 222 struct event ev; 223 struct event report_timer; 224 LIST_HEAD(, iface) iface_list; 225 SIMPLEQ_HEAD(, redistribute) redist_list; 226 227 u_int32_t opts; 228 #define RIPD_OPT_VERBOSE 0x00000001 229 #define RIPD_OPT_VERBOSE2 0x00000002 230 #define RIPD_OPT_NOACTION 0x00000004 231 #define RIPD_OPT_FORCE_DEMOTE 0x00000008 232 int flags; 233 int options; 234 int rip_socket; 235 int redistribute; 236 u_int8_t fib_priority; 237 u_int rdomain; 238 char *csock; 239 }; 240 241 /* kroute */ 242 struct kroute { 243 struct in_addr prefix; 244 struct in_addr netmask; 245 struct in_addr nexthop; 246 u_int16_t flags; 247 u_int16_t rtlabel; 248 u_short ifindex; 249 u_int8_t metric; 250 u_int8_t priority; 251 }; 252 253 struct kif { 254 char ifname[IF_NAMESIZE]; 255 u_int64_t baudrate; 256 int flags; 257 int mtu; 258 u_short ifindex; 259 u_int8_t if_type; 260 u_int8_t link_state; 261 u_int8_t nh_reachable; /* for nexthop verification */ 262 }; 263 264 /* control data structures */ 265 struct ctl_iface { 266 char name[IF_NAMESIZE]; 267 struct in_addr addr; 268 struct in_addr mask; 269 270 time_t uptime; 271 time_t report_timer; 272 273 u_int64_t baudrate; 274 unsigned int ifindex; 275 int state; 276 int mtu; 277 278 u_int16_t flags; 279 u_int16_t metric; 280 enum iface_type type; 281 u_int8_t linkstate; 282 u_int8_t if_type; 283 u_int8_t passive; 284 }; 285 286 struct ctl_rt { 287 struct in_addr prefix; 288 struct in_addr netmask; 289 struct in_addr nexthop; 290 time_t uptime; 291 time_t expire; 292 u_int32_t metric; 293 u_int16_t flags; 294 }; 295 296 struct ctl_nbr { 297 char name[IF_NAMESIZE]; 298 struct in_addr id; 299 struct in_addr addr; 300 time_t dead_timer; 301 time_t uptime; 302 int nbr_state; 303 int iface_state; 304 }; 305 306 struct demote_msg { 307 char demote_group[IF_NAMESIZE]; 308 int level; 309 }; 310 311 int kif_init(void); 312 int kr_init(int, u_int, u_int8_t); 313 int kr_change(struct kroute *); 314 int kr_delete(struct kroute *); 315 void kr_shutdown(void); 316 void kr_fib_couple(void); 317 void kr_fib_decouple(void); 318 void kr_dispatch_msg(int, short, void *); 319 void kr_show_route(struct imsg *); 320 void kr_ifinfo(char *, pid_t); 321 struct kif *kif_findname(char *); 322 323 in_addr_t prefixlen2mask(u_int8_t); 324 u_int8_t mask2prefixlen(in_addr_t); 325 326 /* ripd.c */ 327 void main_imsg_compose_ripe(int, pid_t, void *, u_int16_t); 328 void main_imsg_compose_rde(int, pid_t, void *, u_int16_t); 329 int rip_redistribute(struct kroute *); 330 void imsg_event_add(struct imsgev *); 331 int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, 332 pid_t, int, void *, u_int16_t); 333 334 /* parse.y */ 335 struct ripd_conf *parse_config(char *, int); 336 int cmdline_symset(char *); 337 338 /* carp.c */ 339 int carp_demote_init(char *, int); 340 void carp_demote_shutdown(void); 341 int carp_demote_get(char *); 342 int carp_demote_set(char *, int); 343 344 /* printconf.c */ 345 void print_config(struct ripd_conf *); 346 347 /* logmsg.c */ 348 const char *nbr_state_name(int); 349 const char *if_type_name(enum iface_type); 350 const char *if_auth_name(enum auth_type); 351 const char *if_state_name(int); 352 353 /* interface.c */ 354 struct iface *if_find_index(u_short); 355 356 /* name2id.c */ 357 u_int16_t rtlabel_name2id(const char *); 358 const char *rtlabel_id2name(u_int16_t); 359 void rtlabel_unref(u_int16_t); 360 361 #endif /* RIPD_H */ 362