1 /* $NetBSD: ldp_peer.h,v 1.4 2013/02/04 17:14:31 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 "mpls_routes.h" 40 #include "tlv.h" 41 42 struct ldp_peer_address { 43 union sockunion address; 44 SLIST_ENTRY(ldp_peer_address) addresses; 45 }; 46 47 struct label_mapping { 48 union sockunion address; 49 uint prefix; 50 uint label; 51 SLIST_ENTRY(label_mapping) mappings; 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 sockaddr *address, *transport_address; 61 /* According to draft-ietf-mpls-ldp-ipv6-07 ID is IPv4 only for now */ 62 struct in_addr ldp_id; 63 /* TCP socket */ 64 int socket; 65 /* Rest of the peer parameters */ 66 uint16_t holdtime, timeout; 67 int master; /* 0 if we're passive */ 68 int state; /* see below for possible states */ 69 time_t established_t; /* time when it did connect */ 70 /* Here I maintain all the addresses announced by a peer */ 71 SLIST_HEAD(,ldp_peer_address) ldp_peer_address_head; 72 SLIST_HEAD(,label_mapping) label_mapping_head; 73 74 SLIST_ENTRY(ldp_peer) peers; 75 }; 76 SLIST_HEAD(,ldp_peer) ldp_peer_head; 77 78 struct peer_map { 79 struct ldp_peer *peer; 80 struct label_mapping *lm; 81 }; 82 83 /* LDP Peers States */ 84 #define LDP_PEER_CONNECTING 0 85 #define LDP_PEER_CONNECTED 1 86 #define LDP_PEER_ESTABLISHED 2 87 #define LDP_PEER_HOLDDOWN 3 88 89 int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *); 90 void ldp_peer_init(void); 91 struct ldp_peer * ldp_peer_new(const struct in_addr *, struct sockaddr *, 92 struct sockaddr *, uint16_t, int); 93 void ldp_peer_holddown(struct ldp_peer *); 94 void ldp_peer_delete(struct ldp_peer *); 95 struct ldp_peer * get_ldp_peer(const struct sockaddr *); 96 struct ldp_peer * get_ldp_peer_by_id(const struct in_addr *); 97 struct ldp_peer * get_ldp_peer_by_socket(int); 98 int add_ifaddresses(struct ldp_peer *, struct al_tlv *); 99 int add_ifaddr(struct ldp_peer *, struct sockaddr *); 100 int del_ifaddr(struct ldp_peer *, struct sockaddr *); 101 struct ldp_peer_address * check_ifaddr(struct ldp_peer *, 102 const struct sockaddr *); 103 void print_bounded_addresses(struct ldp_peer *); 104 void del_all_ifaddr(struct ldp_peer *); 105 int del_ifaddresses(struct ldp_peer *, struct al_tlv *); 106 void add_my_if_addrs(struct in_addr *, int); 107 108 int ldp_peer_add_mapping(struct ldp_peer *, struct sockaddr *, int, int); 109 int ldp_peer_delete_mapping(struct ldp_peer *, struct sockaddr *, int); 110 struct label_mapping * ldp_peer_get_lm(struct ldp_peer *, struct sockaddr *, 111 uint); 112 int ldp_peer_delete_all_mappings(struct ldp_peer *); 113 void ldp_peer_holddown_all(void); 114 115 struct peer_map * ldp_test_mapping(struct sockaddr *, int, struct sockaddr *); 116 117 const char * ldp_state_to_name(int); 118 119 #endif /* !_LDP_PEER_H_ */ 120