1 /* $OpenBSD: ldpe.h,v 1.8 2010/05/14 13:49:09 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 u_int32_t label; 35 u_int32_t prefix; 36 u_int8_t prefixlen; 37 }; 38 39 struct nbr { 40 LIST_ENTRY(nbr) entry, hash; 41 struct evbuf wbuf; 42 struct event rev; 43 struct event inactivity_timer; 44 struct event keepalive_timer; 45 struct event keepalive_timeout; 46 struct event initdelay_timer; 47 48 struct mapping_head mapping_list; 49 struct mapping_head withdraw_list; 50 struct mapping_head request_list; 51 struct mapping_head release_list; 52 struct mapping_head abortreq_list; 53 54 struct in_addr addr; 55 struct in_addr id; 56 57 struct buf_read *rbuf; 58 struct iface *iface; 59 60 time_t uptime; 61 u_int32_t peerid; /* unique ID in DB */ 62 63 int fd; 64 int state; 65 66 u_int16_t lspace; 67 u_int16_t holdtime; 68 u_int16_t keepalive; 69 70 u_int8_t priority; 71 u_int8_t options; 72 73 u_int8_t flags; 74 u_int8_t hello_type; 75 76 }; 77 78 /* hello.c */ 79 int send_hello(struct iface *); 80 void recv_hello(struct iface *, struct in_addr, char *, u_int16_t); 81 82 /* init.c */ 83 void send_init(struct nbr *); 84 int recv_init(struct nbr *, char *, u_int16_t); 85 86 /* keepalive.c */ 87 void send_keepalive(struct nbr *); 88 int recv_keepalive(struct nbr *, char *, u_int16_t); 89 90 /* notification.c */ 91 void send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t); 92 struct buf *send_notification(u_int32_t, struct iface *, u_int32_t, 93 u_int32_t); 94 int recv_notification(struct nbr *, char *, u_int16_t); 95 96 /* address.c */ 97 void send_address(struct nbr *, struct iface *); 98 int recv_address(struct nbr *, char *, u_int16_t); 99 void send_address_withdraw(struct nbr *, struct iface *); 100 int recv_address_withdraw(struct nbr *, char *, u_int16_t); 101 102 /* labelmapping.c */ 103 #define PREFIX_SIZE(x) (((x) + 7) / 8) 104 void send_labelmapping(struct nbr *); 105 int recv_labelmapping(struct nbr *, char *, u_int16_t); 106 void send_labelrequest(struct nbr *); 107 int recv_labelrequest(struct nbr *, char *, u_int16_t); 108 void send_labelwithdraw(struct nbr *); 109 int recv_labelwithdraw(struct nbr *, char *, u_int16_t); 110 void send_labelrelease(struct nbr *); 111 int recv_labelrelease(struct nbr *, char *, u_int16_t); 112 void send_labelabortreq(struct nbr *); 113 int recv_labelabortreq(struct nbr *, char *, u_int16_t); 114 115 /* ldpe.c */ 116 pid_t ldpe(struct ldpd_conf *, int[2], int[2], int[2]); 117 void ldpe_dispatch_main(int, short, void *); 118 void ldpe_dispatch_lde(int, short, void *); 119 int ldpe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 120 int ldpe_imsg_compose_lde(int, u_int32_t, pid_t, void *, 121 u_int16_t); 122 u_int32_t ldpe_router_id(void); 123 void ldpe_fib_update(int); 124 void ldpe_iface_ctl(struct ctl_conn *, unsigned int); 125 void ldpe_nbr_ctl(struct ctl_conn *); 126 127 /* interface.c */ 128 int if_fsm(struct iface *, enum iface_event); 129 130 struct iface *if_new(struct kif *, struct kif_addr *); 131 void if_del(struct iface *); 132 void if_init(struct ldpd_conf *, struct iface *); 133 134 int if_act_start(struct iface *); 135 int if_act_reset(struct iface *); 136 137 struct ctl_iface *if_to_ctl(struct iface *); 138 139 int if_join_group(struct iface *, struct in_addr *); 140 int if_leave_group(struct iface *, struct in_addr *); 141 int if_set_mcast(struct iface *); 142 int if_set_recvif(int, int); 143 void if_set_recvbuf(int); 144 int if_set_mcast_loop(int); 145 int if_set_mcast_ttl(int, u_int8_t); 146 int if_set_tos(int, int); 147 int if_set_reuse(int, int); 148 149 /* neighbor.c */ 150 void nbr_init(u_int32_t); 151 struct nbr *nbr_new(u_int32_t, u_int16_t, struct iface *, int); 152 void nbr_del(struct nbr *); 153 154 struct nbr *nbr_find_ip(struct iface *, u_int32_t); 155 struct nbr *nbr_find_ldpid(struct iface *, u_int32_t, u_int16_t); 156 struct nbr *nbr_find_peerid(u_int32_t); 157 158 int nbr_fsm(struct nbr *, enum nbr_event); 159 160 void nbr_itimer(int, short, void *); 161 void nbr_start_itimer(struct nbr *); 162 void nbr_stop_itimer(struct nbr *); 163 void nbr_reset_itimer(struct nbr *); 164 void nbr_ktimer(int, short, void *); 165 void nbr_start_ktimer(struct nbr *); 166 void nbr_stop_ktimer(struct nbr *); 167 void nbr_reset_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_reset_ktimeout(struct nbr *); 172 void nbr_idtimer(int, short, void *); 173 void nbr_start_idtimer(struct nbr *); 174 void nbr_stop_idtimer(struct nbr *); 175 void nbr_reset_idtimer(struct nbr *); 176 int nbr_pending_idtimer(struct nbr *); 177 178 int nbr_act_session_establish(struct nbr *, int); 179 180 void nbr_mapping_add(struct nbr *, struct mapping_head *, 181 struct map *); 182 struct mapping_entry *nbr_mapping_find(struct nbr *, struct mapping_head *, 183 struct map *); 184 void nbr_mapping_del(struct nbr *, struct mapping_head *, 185 struct map *); 186 void nbr_mapping_list_clr(struct nbr *, 187 struct mapping_head *); 188 189 struct ctl_nbr *nbr_to_ctl(struct nbr *); 190 191 /* packet.c */ 192 int gen_ldp_hdr(struct buf *, struct iface *, u_int16_t); 193 int gen_msg_tlv(struct buf *, u_int32_t, u_int16_t); 194 int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); 195 void disc_recv_packet(int, short, void *); 196 void session_accept(int, short, void *); 197 198 void session_read(int, short, void *); 199 void session_write(int, short, void *); 200 void session_close(struct nbr *); 201 void session_shutdown(struct nbr *, u_int32_t, u_int32_t, u_int32_t); 202 203 char *pkt_ptr; /* packet buffer */ 204 205 #endif /* _LDPE_H_ */ 206