1 /* $OpenBSD: ldpe.h,v 1.16 2012/04/12 17:33:43 claudio Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef _LDPE_H_ 20 #define _LDPE_H_ 21 22 #define max(x,y) ((x) > (y) ? (x) : (y)) 23 24 #include <sys/types.h> 25 #include <sys/socket.h> 26 #include <netinet/in.h> 27 #include <netinet/in_systm.h> 28 #include <netinet/ip.h> 29 30 TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; 31 32 struct mapping_entry { 33 TAILQ_ENTRY(mapping_entry) entry; 34 struct map map; 35 }; 36 37 struct nbr { 38 RB_ENTRY(nbr) id_tree, addr_tree, pid_tree; 39 struct evbuf wbuf; 40 struct event rev; 41 struct event inactivity_timer; 42 struct event keepalive_timer; 43 struct event keepalive_timeout; 44 struct event initdelay_timer; 45 46 struct mapping_head mapping_list; 47 struct mapping_head withdraw_list; 48 struct mapping_head request_list; 49 struct mapping_head release_list; 50 struct mapping_head abortreq_list; 51 52 struct in_addr addr; 53 struct in_addr id; 54 55 struct ibuf_read *rbuf; 56 struct iface *iface; 57 58 time_t uptime; 59 u_int32_t peerid; /* unique ID in DB */ 60 61 int fd; 62 int state; 63 64 u_int16_t lspace; 65 u_int16_t holdtime; 66 u_int16_t keepalive; 67 68 u_int8_t priority; 69 u_int8_t options; 70 71 u_int8_t flags; 72 u_int8_t hello_type; 73 74 }; 75 76 /* accept.c */ 77 void accept_init(void); 78 int accept_add(int, void (*)(int, short, void *), void *); 79 void accept_del(int); 80 void accept_pause(void); 81 void accept_unpause(void); 82 83 /* hello.c */ 84 int send_hello(struct iface *); 85 void recv_hello(struct iface *, struct in_addr, char *, u_int16_t); 86 87 /* init.c */ 88 void send_init(struct nbr *); 89 int recv_init(struct nbr *, char *, u_int16_t); 90 91 /* keepalive.c */ 92 void send_keepalive(struct nbr *); 93 int recv_keepalive(struct nbr *, char *, u_int16_t); 94 95 /* notification.c */ 96 void send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t); 97 struct ibuf *send_notification(u_int32_t, struct iface *, u_int32_t, 98 u_int32_t); 99 int recv_notification(struct nbr *, char *, u_int16_t); 100 101 /* address.c */ 102 void send_address(struct nbr *, struct iface *); 103 int recv_address(struct nbr *, char *, u_int16_t); 104 void send_address_withdraw(struct nbr *, struct iface *); 105 106 /* labelmapping.c */ 107 #define PREFIX_SIZE(x) (((x) + 7) / 8) 108 void send_labelmapping(struct nbr *); 109 int recv_labelmapping(struct nbr *, char *, u_int16_t); 110 void send_labelrequest(struct nbr *); 111 int recv_labelrequest(struct nbr *, char *, u_int16_t); 112 void send_labelwithdraw(struct nbr *); 113 int recv_labelwithdraw(struct nbr *, char *, u_int16_t); 114 void send_labelrelease(struct nbr *); 115 int recv_labelrelease(struct nbr *, char *, u_int16_t); 116 void send_labelabortreq(struct nbr *); 117 int recv_labelabortreq(struct nbr *, char *, u_int16_t); 118 119 /* ldpe.c */ 120 pid_t ldpe(struct ldpd_conf *, int[2], int[2], int[2]); 121 void ldpe_dispatch_main(int, short, void *); 122 void ldpe_dispatch_lde(int, short, void *); 123 int ldpe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 124 int ldpe_imsg_compose_lde(int, u_int32_t, pid_t, void *, 125 u_int16_t); 126 u_int32_t ldpe_router_id(void); 127 void ldpe_fib_update(int); 128 void ldpe_iface_ctl(struct ctl_conn *, unsigned int); 129 130 /* interface.c */ 131 int if_fsm(struct iface *, enum iface_event); 132 133 struct iface *if_new(struct kif *, struct kif_addr *); 134 void if_del(struct iface *); 135 void if_init(struct ldpd_conf *, struct iface *); 136 137 int if_act_start(struct iface *); 138 int if_act_reset(struct iface *); 139 140 struct ctl_iface *if_to_ctl(struct iface *); 141 142 int if_join_group(struct iface *, struct in_addr *); 143 int if_leave_group(struct iface *, struct in_addr *); 144 int if_set_mcast(struct iface *); 145 int if_set_recvif(int, int); 146 void if_set_recvbuf(int); 147 int if_set_mcast_loop(int); 148 int if_set_mcast_ttl(int, u_int8_t); 149 int if_set_tos(int, int); 150 int if_set_reuse(int, int); 151 152 /* neighbor.c */ 153 struct nbr *nbr_new(u_int32_t, u_int16_t, struct iface *, struct in_addr); 154 void nbr_del(struct nbr *); 155 156 struct nbr *nbr_find_ip(u_int32_t); 157 struct nbr *nbr_find_ldpid(u_int32_t, u_int16_t); 158 struct nbr *nbr_find_peerid(u_int32_t); 159 160 int nbr_fsm(struct nbr *, enum nbr_event); 161 162 void nbr_itimer(int, short, void *); 163 void nbr_start_itimer(struct nbr *); 164 void nbr_stop_itimer(struct nbr *); 165 void nbr_ktimer(int, short, void *); 166 void nbr_start_ktimer(struct nbr *); 167 void nbr_stop_ktimer(struct nbr *); 168 void nbr_ktimeout(int, short, void *); 169 void nbr_start_ktimeout(struct nbr *); 170 void nbr_stop_ktimeout(struct nbr *); 171 void nbr_idtimer(int, short, void *); 172 void nbr_start_idtimer(struct nbr *); 173 void nbr_stop_idtimer(struct nbr *); 174 int nbr_pending_idtimer(struct nbr *); 175 176 int nbr_act_session_establish(struct nbr *, int); 177 178 void nbr_mapping_add(struct nbr *, struct mapping_head *, 179 struct map *); 180 struct mapping_entry *nbr_mapping_find(struct nbr *, struct mapping_head *, 181 struct map *); 182 void nbr_mapping_del(struct nbr *, struct mapping_head *, 183 struct map *); 184 void nbr_mapping_list_clr(struct nbr *, 185 struct mapping_head *); 186 187 struct ctl_nbr *nbr_to_ctl(struct nbr *); 188 void ldpe_nbr_ctl(struct ctl_conn *); 189 190 /* packet.c */ 191 int gen_ldp_hdr(struct ibuf *, struct iface *, u_int16_t); 192 int gen_msg_tlv(struct ibuf *, u_int32_t, u_int16_t); 193 int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); 194 void disc_recv_packet(int, short, void *); 195 void session_accept(int, short, void *); 196 197 void session_read(int, short, void *); 198 void session_write(int, short, void *); 199 void session_close(struct nbr *); 200 void session_shutdown(struct nbr *, u_int32_t, u_int32_t, u_int32_t); 201 202 char *pkt_ptr; /* packet buffer */ 203 204 #endif /* _LDPE_H_ */ 205