1 /* $NetBSD: ldp_peer.h,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Mihai Chelaru <kefren@NetBSD.org> 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _LDP_PEER_H_ 33 #define _LDP_PEER_H_ 34 35 #include "sys/types.h" 36 #include "sys/queue.h" 37 #include "netinet/in.h" 38 39 #include "tlv.h" 40 41 struct ldp_peer_address { 42 struct in_addr address; 43 SLIST_ENTRY(ldp_peer_address) addresses; 44 }; 45 46 struct label_mapping { 47 struct in_addr address; 48 int prefix; 49 int label; 50 SLIST_ENTRY(label_mapping) mappings; 51 }; 52 53 54 struct ldp_peer { 55 /* 56 * I add routes to address. 57 * I maintain LDP TCP connection on transport_address. 58 * I use ldp_id as peer identificator. 59 */ 60 struct in_addr address, transport_address, ldp_id; 61 /* TCP socket */ 62 int socket; 63 /* Usual peer parameters */ 64 uint16_t holdtime, timeout; 65 int master; /* 0 if we're passive */ 66 int state; /* see below for possible states */ 67 time_t established_t; /* time when it did connected */ 68 /* Here I maintain all the addresses announced by a peer */ 69 SLIST_HEAD(,ldp_peer_address) ldp_peer_address_head; 70 SLIST_HEAD(,label_mapping) label_mapping_head; 71 72 SLIST_ENTRY(ldp_peer) peers; 73 }; 74 SLIST_HEAD(,ldp_peer) ldp_peer_head; 75 76 struct peer_map { 77 struct ldp_peer *peer; 78 struct label_mapping *lm; 79 }; 80 81 /* LDP Peers States */ 82 #define LDP_PEER_CONNECTING 0 83 #define LDP_PEER_CONNECTED 1 84 #define LDP_PEER_ESTABLISHED 2 85 #define LDP_PEER_HOLDDOWN 3 86 87 void ldp_peer_init(void); 88 struct ldp_peer * ldp_peer_new(struct in_addr *, struct in_addr *, 89 struct in_addr *, uint16_t, int); 90 void ldp_peer_holddown(struct ldp_peer *); 91 void ldp_peer_delete(struct ldp_peer *); 92 struct ldp_peer * get_ldp_peer(struct in_addr *); 93 struct ldp_peer * get_ldp_peer_by_socket(int); 94 int add_ifaddresses(struct ldp_peer *, struct al_tlv *); 95 int add_ifaddr(struct ldp_peer *, struct in_addr *); 96 int del_ifaddr(struct ldp_peer *, struct in_addr *); 97 struct ldp_peer_address * check_ifaddr(struct ldp_peer *, 98 struct in_addr *); 99 void print_bounded_addresses(struct ldp_peer *); 100 void del_all_ifaddr(struct ldp_peer *); 101 int del_ifaddresses(struct ldp_peer *, struct al_tlv *); 102 void add_my_if_addrs(struct in_addr *, int); 103 104 int ldp_peer_add_mapping(struct ldp_peer *, struct in_addr *, 105 int, int); 106 int ldp_peer_delete_mapping(struct ldp_peer *, struct in_addr *, 107 int); 108 struct label_mapping * ldp_peer_get_lm(struct ldp_peer *, struct in_addr *, 109 int); 110 int ldp_peer_delete_all_mappings(struct ldp_peer *); 111 void ldp_peer_holddown_all(void); 112 113 struct peer_map * ldp_test_mapping(struct in_addr *, int, 114 struct in_addr *); 115 116 const char * ldp_state_to_name(int); 117 118 #endif /* !_LDP_PEER_H_ */ 119