1 /* $OpenBSD: ldpe.h,v 1.77 2019/12/12 00:10:29 yasuoka Exp $ */ 2 3 /* 4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org> 5 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> 6 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21 #ifndef _LDPE_H_ 22 #define _LDPE_H_ 23 24 #include <sys/types.h> 25 #include <sys/queue.h> 26 #include <sys/tree.h> 27 #include <net/pfkeyv2.h> 28 29 #include "ldpd.h" 30 31 #define min(x,y) ((x) <= (y) ? (x) : (y)) 32 #define max(x,y) ((x) > (y) ? (x) : (y)) 33 34 struct hello_source { 35 enum hello_type type; 36 struct in_addr lsr_id; 37 struct { 38 struct iface_af *ia; 39 union ldpd_addr src_addr; 40 } link; 41 struct tnbr *target; 42 }; 43 44 struct adj { 45 LIST_ENTRY(adj) global_entry; 46 LIST_ENTRY(adj) nbr_entry; 47 LIST_ENTRY(adj) ia_entry; 48 struct in_addr lsr_id; 49 struct nbr *nbr; 50 int ds_tlv; 51 struct hello_source source; 52 struct event inactivity_timer; 53 uint16_t holdtime; 54 union ldpd_addr trans_addr; 55 }; 56 57 struct tcp_conn { 58 struct nbr *nbr; 59 int fd; 60 struct ibuf_read *rbuf; 61 struct evbuf wbuf; 62 struct event rev; 63 }; 64 65 struct nbr { 66 RB_ENTRY(nbr) id_tree, addr_tree, pid_tree; 67 struct tcp_conn *tcp; 68 LIST_HEAD(, adj) adj_list; /* adjacencies */ 69 struct event ev_connect; 70 struct event keepalive_timer; 71 struct event keepalive_timeout; 72 struct event init_timeout; 73 struct event initdelay_timer; 74 75 struct mapping_head mapping_list; 76 struct mapping_head withdraw_list; 77 struct mapping_head request_list; 78 struct mapping_head release_list; 79 struct mapping_head abortreq_list; 80 81 uint32_t peerid; /* unique ID in DB */ 82 int af; 83 int ds_tlv; 84 int v4_enabled; /* announce/process v4 msgs */ 85 int v6_enabled; /* announce/process v6 msgs */ 86 struct in_addr id; /* lsr id */ 87 union ldpd_addr laddr; /* local address */ 88 union ldpd_addr raddr; /* remote address */ 89 uint32_t raddr_scope; /* remote address scope (v6) */ 90 time_t uptime; 91 int fd; 92 int state; 93 uint32_t conf_seqnum; 94 int idtimer_cnt; 95 uint16_t keepalive; 96 uint16_t max_pdu_len; 97 98 uint32_t auth_spi_in; 99 uint32_t auth_spi_out; 100 int auth_established; 101 102 int flags; 103 }; 104 #define F_NBR_GTSM_NEGOTIATED 0x01 105 #define F_NBR_CAP_DYNAMIC 0x02 106 #define F_NBR_CAP_TWCARD 0x04 107 #define F_NBR_CAP_UNOTIF 0x08 108 109 RB_HEAD(nbr_id_head, nbr); 110 RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare) 111 RB_HEAD(nbr_addr_head, nbr); 112 RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare) 113 RB_HEAD(nbr_pid_head, nbr); 114 RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) 115 116 struct pending_conn { 117 TAILQ_ENTRY(pending_conn) entry; 118 int fd; 119 int af; 120 union ldpd_addr addr; 121 struct event ev_timeout; 122 }; 123 #define PENDING_CONN_TIMEOUT 5 124 125 struct mapping_entry { 126 TAILQ_ENTRY(mapping_entry) entry; 127 struct map map; 128 }; 129 130 struct ldpd_sysdep { 131 uint8_t no_pfkey; 132 uint8_t no_md5sig; 133 }; 134 135 extern struct ldpd_conf *leconf; 136 extern struct ldpd_sysdep sysdep; 137 extern struct nbr_id_head nbrs_by_id; 138 extern struct nbr_addr_head nbrs_by_addr; 139 extern struct nbr_pid_head nbrs_by_pid; 140 141 /* accept.c */ 142 void accept_init(void); 143 int accept_add(int, void (*)(int, short, void *), void *); 144 void accept_del(int); 145 void accept_pause(void); 146 void accept_unpause(void); 147 148 /* hello.c */ 149 int send_hello(enum hello_type, struct iface_af *, struct tnbr *); 150 void recv_hello(struct in_addr, struct ldp_msg *, int, union ldpd_addr *, 151 struct iface *, int, char *, uint16_t); 152 153 /* init.c */ 154 void send_init(struct nbr *); 155 int recv_init(struct nbr *, char *, uint16_t); 156 void send_capability(struct nbr *, uint16_t, int); 157 int recv_capability(struct nbr *, char *, uint16_t); 158 159 /* keepalive.c */ 160 void send_keepalive(struct nbr *); 161 int recv_keepalive(struct nbr *, char *, uint16_t); 162 163 /* notification.c */ 164 void send_notification_full(struct tcp_conn *, struct notify_msg *); 165 void send_notification(struct tcp_conn *, uint32_t, uint32_t, uint16_t); 166 void send_notification_rtlvs(struct nbr *, uint32_t, uint32_t, uint16_t, 167 uint16_t, uint16_t, char *); 168 int recv_notification(struct nbr *, char *, uint16_t); 169 int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint16_t); 170 171 /* address.c */ 172 void send_address_single(struct nbr *, struct if_addr *, int); 173 void send_address_all(struct nbr *, int); 174 void send_mac_withdrawal(struct nbr *, struct map *, uint8_t *); 175 int recv_address(struct nbr *, char *, uint16_t); 176 177 /* labelmapping.c */ 178 #define PREFIX_SIZE(x) (((x) + 7) / 8) 179 void send_labelmessage(struct nbr *, uint16_t, struct mapping_head *); 180 int recv_labelmessage(struct nbr *, char *, uint16_t, uint16_t); 181 int gen_pw_status_tlv(struct ibuf *, uint32_t); 182 uint16_t len_fec_tlv(struct map *); 183 int gen_fec_tlv(struct ibuf *, struct map *); 184 int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *, 185 uint16_t, struct map *); 186 187 /* ldpe.c */ 188 void ldpe(int, int, char *); 189 int ldpe_imsg_compose_parent(int, pid_t, void *, 190 uint16_t); 191 int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *, 192 uint16_t); 193 void ldpe_reset_nbrs(int); 194 void ldpe_reset_ds_nbrs(void); 195 void ldpe_remove_dynamic_tnbrs(int); 196 void ldpe_stop_init_backoff(int); 197 struct ctl_conn; 198 void ldpe_iface_ctl(struct ctl_conn *, unsigned int); 199 void ldpe_adj_ctl(struct ctl_conn *); 200 void ldpe_nbr_ctl(struct ctl_conn *); 201 void mapping_list_add(struct mapping_head *, struct map *); 202 void mapping_list_clr(struct mapping_head *); 203 204 /* interface.c */ 205 struct iface *if_new(struct kif *); 206 void if_exit(struct iface *); 207 struct iface *if_lookup(struct ldpd_conf *, unsigned short); 208 struct iface_af *iface_af_get(struct iface *, int); 209 void if_addr_add(struct kaddr *); 210 void if_addr_del(struct kaddr *); 211 void if_update(struct iface *, int); 212 void if_update_all(int); 213 struct ctl_iface *if_to_ctl(struct iface_af *); 214 in_addr_t if_get_ipv4_addr(struct iface *); 215 216 /* adjacency.c */ 217 struct adj *adj_new(struct in_addr, struct hello_source *, 218 union ldpd_addr *); 219 void adj_del(struct adj *, uint32_t); 220 struct adj *adj_find(struct hello_source *); 221 int adj_get_af(struct adj *adj); 222 void adj_start_itimer(struct adj *); 223 void adj_stop_itimer(struct adj *); 224 struct tnbr *tnbr_new(struct ldpd_conf *, int, union ldpd_addr *); 225 struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *); 226 struct tnbr *tnbr_check(struct tnbr *); 227 void tnbr_update(struct tnbr *); 228 void tnbr_update_all(int); 229 struct ctl_adj *adj_to_ctl(struct adj *); 230 231 /* neighbor.c */ 232 int nbr_fsm(struct nbr *, enum nbr_event); 233 struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *, 234 uint32_t); 235 void nbr_del(struct nbr *); 236 struct nbr *nbr_find_ldpid(uint32_t); 237 struct nbr *nbr_find_addr(int, union ldpd_addr *); 238 struct nbr *nbr_find_peerid(uint32_t); 239 int nbr_adj_count(struct nbr *, int); 240 int nbr_session_active_role(struct nbr *); 241 void nbr_stop_ktimer(struct nbr *); 242 void nbr_stop_ktimeout(struct nbr *); 243 void nbr_stop_itimeout(struct nbr *); 244 void nbr_start_idtimer(struct nbr *); 245 void nbr_stop_idtimer(struct nbr *); 246 int nbr_pending_idtimer(struct nbr *); 247 int nbr_pending_connect(struct nbr *); 248 int nbr_establish_connection(struct nbr *); 249 int nbr_gtsm_enabled(struct nbr *, struct nbr_params *); 250 int nbr_gtsm_setup(int, int, struct nbr_params *); 251 int nbr_gtsm_check(int, struct nbr *, struct nbr_params *); 252 struct nbr_params *nbr_params_new(struct in_addr); 253 struct nbr_params *nbr_params_find(struct ldpd_conf *, struct in_addr); 254 uint16_t nbr_get_keepalive(int, struct in_addr); 255 struct ctl_nbr *nbr_to_ctl(struct nbr *); 256 void nbr_clear_ctl(struct ctl_nbr *); 257 258 /* packet.c */ 259 int gen_ldp_hdr(struct ibuf *, uint16_t); 260 int gen_msg_hdr(struct ibuf *, uint16_t, uint16_t); 261 int send_packet(int, int, union ldpd_addr *, 262 struct iface_af *, void *, size_t); 263 void disc_recv_packet(int, short, void *); 264 void session_accept(int, short, void *); 265 void session_accept_nbr(struct nbr *, int); 266 void session_shutdown(struct nbr *, uint32_t, uint32_t, 267 uint32_t); 268 void session_close(struct nbr *); 269 struct tcp_conn *tcp_new(int, struct nbr *); 270 void pending_conn_del(struct pending_conn *); 271 struct pending_conn *pending_conn_find(int, union ldpd_addr *); 272 273 char *pkt_ptr; /* packet buffer */ 274 275 /* pfkey.c */ 276 int pfkey_read(int, struct sadb_msg *); 277 int pfkey_establish(struct ldpd_conf *, struct nbr *); 278 int pfkey_remove(struct nbr *); 279 int pfkey_init(void); 280 281 /* l2vpn.c */ 282 void ldpe_l2vpn_init(struct l2vpn *); 283 void ldpe_l2vpn_exit(struct l2vpn *); 284 void ldpe_l2vpn_pw_init(struct l2vpn_pw *); 285 void ldpe_l2vpn_pw_exit(struct l2vpn_pw *); 286 287 #endif /* _LDPE_H_ */ 288