1 /* $OpenBSD: ldpe.h,v 1.15 2011/03/12 01:57:13 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 /* hello.c */ 77 int send_hello(struct iface *); 78 void recv_hello(struct iface *, struct in_addr, char *, u_int16_t); 79 80 /* init.c */ 81 void send_init(struct nbr *); 82 int recv_init(struct nbr *, char *, u_int16_t); 83 84 /* keepalive.c */ 85 void send_keepalive(struct nbr *); 86 int recv_keepalive(struct nbr *, char *, u_int16_t); 87 88 /* notification.c */ 89 void send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t); 90 struct ibuf *send_notification(u_int32_t, struct iface *, u_int32_t, 91 u_int32_t); 92 int recv_notification(struct nbr *, char *, u_int16_t); 93 94 /* address.c */ 95 void send_address(struct nbr *, struct iface *); 96 int recv_address(struct nbr *, char *, u_int16_t); 97 void send_address_withdraw(struct nbr *, struct iface *); 98 99 /* labelmapping.c */ 100 #define PREFIX_SIZE(x) (((x) + 7) / 8) 101 void send_labelmapping(struct nbr *); 102 int recv_labelmapping(struct nbr *, char *, u_int16_t); 103 void send_labelrequest(struct nbr *); 104 int recv_labelrequest(struct nbr *, char *, u_int16_t); 105 void send_labelwithdraw(struct nbr *); 106 int recv_labelwithdraw(struct nbr *, char *, u_int16_t); 107 void send_labelrelease(struct nbr *); 108 int recv_labelrelease(struct nbr *, char *, u_int16_t); 109 void send_labelabortreq(struct nbr *); 110 int recv_labelabortreq(struct nbr *, char *, u_int16_t); 111 112 /* ldpe.c */ 113 pid_t ldpe(struct ldpd_conf *, int[2], int[2], int[2]); 114 void ldpe_dispatch_main(int, short, void *); 115 void ldpe_dispatch_lde(int, short, void *); 116 int ldpe_imsg_compose_parent(int, pid_t, void *, u_int16_t); 117 int ldpe_imsg_compose_lde(int, u_int32_t, pid_t, void *, 118 u_int16_t); 119 u_int32_t ldpe_router_id(void); 120 void ldpe_fib_update(int); 121 void ldpe_iface_ctl(struct ctl_conn *, unsigned int); 122 123 /* interface.c */ 124 int if_fsm(struct iface *, enum iface_event); 125 126 struct iface *if_new(struct kif *, struct kif_addr *); 127 void if_del(struct iface *); 128 void if_init(struct ldpd_conf *, struct iface *); 129 130 int if_act_start(struct iface *); 131 int if_act_reset(struct iface *); 132 133 struct ctl_iface *if_to_ctl(struct iface *); 134 135 int if_join_group(struct iface *, struct in_addr *); 136 int if_leave_group(struct iface *, struct in_addr *); 137 int if_set_mcast(struct iface *); 138 int if_set_recvif(int, int); 139 void if_set_recvbuf(int); 140 int if_set_mcast_loop(int); 141 int if_set_mcast_ttl(int, u_int8_t); 142 int if_set_tos(int, int); 143 int if_set_reuse(int, int); 144 145 /* neighbor.c */ 146 struct nbr *nbr_new(u_int32_t, u_int16_t, struct iface *, struct in_addr); 147 void nbr_del(struct nbr *); 148 149 struct nbr *nbr_find_ip(u_int32_t); 150 struct nbr *nbr_find_ldpid(u_int32_t, u_int16_t); 151 struct nbr *nbr_find_peerid(u_int32_t); 152 153 int nbr_fsm(struct nbr *, enum nbr_event); 154 155 void nbr_itimer(int, short, void *); 156 void nbr_start_itimer(struct nbr *); 157 void nbr_stop_itimer(struct nbr *); 158 void nbr_ktimer(int, short, void *); 159 void nbr_start_ktimer(struct nbr *); 160 void nbr_stop_ktimer(struct nbr *); 161 void nbr_ktimeout(int, short, void *); 162 void nbr_start_ktimeout(struct nbr *); 163 void nbr_stop_ktimeout(struct nbr *); 164 void nbr_idtimer(int, short, void *); 165 void nbr_start_idtimer(struct nbr *); 166 void nbr_stop_idtimer(struct nbr *); 167 int nbr_pending_idtimer(struct nbr *); 168 169 int nbr_act_session_establish(struct nbr *, int); 170 171 void nbr_mapping_add(struct nbr *, struct mapping_head *, 172 struct map *); 173 struct mapping_entry *nbr_mapping_find(struct nbr *, struct mapping_head *, 174 struct map *); 175 void nbr_mapping_del(struct nbr *, struct mapping_head *, 176 struct map *); 177 void nbr_mapping_list_clr(struct nbr *, 178 struct mapping_head *); 179 180 struct ctl_nbr *nbr_to_ctl(struct nbr *); 181 void ldpe_nbr_ctl(struct ctl_conn *); 182 183 /* packet.c */ 184 int gen_ldp_hdr(struct ibuf *, struct iface *, u_int16_t); 185 int gen_msg_tlv(struct ibuf *, u_int32_t, u_int16_t); 186 int send_packet(struct iface *, void *, size_t, struct sockaddr_in *); 187 void disc_recv_packet(int, short, void *); 188 void session_accept(int, short, void *); 189 190 void session_read(int, short, void *); 191 void session_write(int, short, void *); 192 void session_close(struct nbr *); 193 void session_shutdown(struct nbr *, u_int32_t, u_int32_t, u_int32_t); 194 195 char *pkt_ptr; /* packet buffer */ 196 197 #endif /* _LDPE_H_ */ 198