Home | History | Annotate | Line # | Download | only in ldpd
      1 /* $NetBSD: ldp_peer.h,v 1.9 2020/04/22 23:53:27 joerg 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 (at) 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/rbtree.h"
     37 #include "sys/queue.h"
     38 #include "netinet/in.h"
     39 
     40 #include "mpls_routes.h"
     41 #include "tlv.h"
     42 
     43 struct ldp_peer_address {
     44 	union sockunion address;
     45 	SLIST_ENTRY(ldp_peer_address) addresses;
     46 };
     47 
     48 struct label_mapping {
     49 	union sockunion address;
     50 	uint	prefix;
     51 	uint	label;
     52 	rb_node_t mappings_node;
     53 };
     54 
     55 struct ldp_peer {
     56 	/*
     57 	 * I add routes to address.
     58 	 * I maintain LDP TCP connection on transport_address.
     59 	 * I use ldp_id as peer identificator.
     60 	 */
     61 	struct sockaddr *address, *transport_address;
     62 	/* According to draft-ietf-mpls-ldp-ipv6-07 ID is IPv4 only for now */
     63 	struct in_addr	ldp_id;
     64 	/* TCP socket */
     65 	int             socket;
     66 	/* Rest of the peer parameters */
     67 	uint16_t	holdtime, timeout;
     68 	int		master;	/* 0 if we're passive */
     69 	int		state;	/* see below for possible states */
     70 	time_t		established_t;	/* time when it did connect */
     71 	/* Here I maintain all the addresses announced by a peer */
     72 	SLIST_HEAD(,ldp_peer_address) ldp_peer_address_head;
     73 	rb_tree_t label_mapping_tree;
     74 
     75 	SLIST_ENTRY(ldp_peer) peers;
     76 };
     77 extern SLIST_HEAD(ldp_peer_head,ldp_peer) ldp_peer_head;
     78 
     79 struct peer_map {
     80 	struct ldp_peer *peer;
     81 	struct label_mapping *lm;
     82 };
     83 
     84 /* LDP Peers States */
     85 #define	LDP_PEER_CONNECTING	0
     86 #define	LDP_PEER_CONNECTED	1
     87 #define	LDP_PEER_ESTABLISHED	2
     88 #define	LDP_PEER_HOLDDOWN	3
     89 
     90 int	sockaddr_cmp(const struct sockaddr *, const struct sockaddr *);
     91 void            ldp_peer_init(void);
     92 struct ldp_peer * ldp_peer_new(const struct in_addr *, const struct sockaddr *,
     93 				const struct sockaddr *, uint16_t, int);
     94 void            ldp_peer_holddown(struct ldp_peer *);
     95 void            ldp_peer_delete(struct ldp_peer *);
     96 struct ldp_peer * get_ldp_peer(const struct sockaddr *);
     97 struct ldp_peer * get_ldp_peer_by_id(const struct in_addr *);
     98 struct ldp_peer * get_ldp_peer_by_socket(int);
     99 int add_ifaddresses(struct ldp_peer *, const struct al_tlv *);
    100 int add_ifaddr(struct ldp_peer *, const struct sockaddr *);
    101 int del_ifaddr(struct ldp_peer *, const struct sockaddr *);
    102 struct ldp_peer_address * check_ifaddr(const struct ldp_peer *,
    103 	const struct sockaddr *);
    104 void print_bounded_addresses(const struct ldp_peer *);
    105 void del_all_ifaddr(struct ldp_peer *);
    106 int del_ifaddresses(struct ldp_peer *, const struct al_tlv *);
    107 
    108 int ldp_peer_add_mapping(struct ldp_peer *, const struct sockaddr *, int, int);
    109 int ldp_peer_delete_mapping(struct ldp_peer *, const struct sockaddr *, int);
    110 void ldp_peer_delete_all_mappings(struct ldp_peer *);
    111 void ldp_peer_holddown_all(void);
    112 
    113 struct peer_map * ldp_test_mapping(const struct sockaddr *, int,
    114 	const struct sockaddr *);
    115 struct label_mapping * ldp_peer_lm_right(struct ldp_peer *,
    116 	struct label_mapping *);
    117 
    118 const char * ldp_state_to_name(int);
    119 
    120 #endif	/* !_LDP_PEER_H_ */
    121