Home | History | Annotate | Line # | Download | only in lagg
if_lagg_lacp.h revision 1.2
      1 /*	$NetBSD: if_lagg_lacp.h,v 1.2 2021/05/24 06:08:28 yamaguchi Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2021 Internet Initiative Japan Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _NET_LAGG_IF_LAGG_LACP_H_
     30 #define _NET_LAGG_IF_LAGG_LACP_H_
     31 
     32 /* timeout values (in sec) */
     33 #define LACP_FAST_PERIODIC_TIME		1
     34 #define LACP_SLOW_PERIODIC_TIME		30
     35 #define LACP_SHORT_TIMEOUT_TIME		(3 * LACP_FAST_PERIODIC_TIME)
     36 #define LACP_LONG_TIMEOUT_TIME		(3 * LACP_SLOW_PERIODIC_TIME)
     37 #define LACP_CHURN_DETECTION_TIME	60
     38 #define LACP_AGGREGATE_WAIT_TIME	2
     39 #define LACP_TRANSIT_DELAY		3
     40 
     41 #define LACP_MAX_PORTS		16
     42 #define LACP_SYSTEM_PRIO	0x8000U
     43 #define LACP_PORT_PRIO		LAGG_PORT_PRIO
     44 
     45 #define LACP_PARTNER_ADMIN_OPTIMISTIC	(LACP_STATE_SYNC | \
     46 					LACP_STATE_AGGREGATION | \
     47 					LACP_STATE_COLLECTING | \
     48 					LACP_STATE_DISTRIBUTING)
     49 #define LACP_PARTNER_ADMIN_STRICT	0
     50 
     51 #define SLOWPROTOCOLS_SUBTYPE_LACP	1
     52 #define SLOWPROTOCOLS_SUBTYPE_MARKER	2
     53 
     54 struct slowprothdr {
     55 	uint8_t		 sph_subtype;
     56 	uint8_t		 sph_version;
     57 } __packed;
     58 
     59 #define TLV_TYPE_TERMINATE	0
     60 
     61 #define LACP_TYPE_TERMINATE	TLV_TYPE_TERMINATE
     62 #define LACP_TYPE_ACTORINFO	1
     63 #define LACP_TYPE_PARTNERINFO	2
     64 #define LACP_TYPE_COLLECTORINFO	3
     65 
     66 #define MARKER_TYPE_TERMINATE	TLV_TYPE_TERMINATE
     67 #define MARKER_TYPE_INFO	1
     68 #define MARKER_TYPE_RESPONSE	2
     69 
     70 struct tlvhdr {
     71 	uint8_t		 tlv_type;
     72 	uint8_t		 tlv_length;
     73 } __packed;
     74 
     75 struct tlv {
     76 	uint8_t		 tlv_t;
     77 	uint8_t		 tlv_l;
     78 	void		*tlv_v;
     79 };
     80 
     81 static inline void
     82 tlv_set(struct tlvhdr *th, uint8_t t, uint8_t l)
     83 {
     84 
     85 	th->tlv_type = t;
     86 	th->tlv_length = sizeof(*th) + l;
     87 }
     88 
     89 struct lacpdu_peerinfo {
     90 	uint16_t	 lpi_system_prio;
     91 	uint8_t		 lpi_system_mac[LACP_MAC_LEN];
     92 	uint16_t	 lpi_key;
     93 	uint16_t	 lpi_port_prio;
     94 	uint16_t	 lpi_port_no;
     95 	uint8_t		 lpi_state;
     96 	uint8_t		 lpi_resv[3];
     97 } __packed;
     98 
     99 struct lacpdu_collectorinfo {
    100 	uint16_t	 lci_maxdelay;
    101 	uint8_t		 lci_resv[12];
    102 } __packed;
    103 
    104 struct lacpdu {
    105 	struct ether_header	 ldu_eh;
    106 	struct slowprothdr	 ldu_sph;
    107 
    108 	struct tlvhdr		 ldu_tlv_actor;
    109 	struct lacpdu_peerinfo	 ldu_actor;
    110 	struct tlvhdr		 ldu_tlv_partner;
    111 	struct lacpdu_peerinfo	 ldu_partner;
    112 
    113 	struct tlvhdr		 ldu_tlv_collector;
    114 	struct lacpdu_collectorinfo
    115 				 ldu_collector;
    116 
    117 	struct tlvhdr		 ldu_tlv_term;
    118 	uint8_t			 ldu_resv[50];
    119 } __packed;
    120 
    121 struct markerdu_info {
    122 	uint16_t	 mi_rq_port;
    123 	uint8_t		 mi_rq_system[LACP_MAC_LEN];
    124 	uint32_t	 mi_rq_xid;
    125 	uint8_t		 mi_pad[2];
    126 } __packed;
    127 
    128 struct markerdu {
    129 	struct ether_header	 mdu_eh;
    130 	struct slowprothdr	 mdu_sph;
    131 
    132 	struct tlvhdr		 mdu_tlv_info;
    133 	struct markerdu_info	 mdu_info;
    134 
    135 	struct tlvhdr		 mdu_tlv_term;
    136 	uint8_t			 mdu_resv[90];
    137 } __packed;
    138 
    139 /*
    140  * lacp media:
    141  *   1byte
    142  * +-------+-------+-------+-------+
    143  * | media |                 speed |
    144  * +-------+-------+-------+-------+
    145  */
    146 
    147 enum lacp_linkspeed {
    148 	LACP_LINKSPEED_UNKNOWN = 0,
    149 	LACP_LINKSPEED_10,
    150 	LACP_LINKSPEED_100,
    151 	LACP_LINKSPEED_1000,
    152 	LACP_LINKSPEED_2500,
    153 	LACP_LINKSPEED_5000,
    154 	LACP_LINKSPEED_10G,
    155 	LACP_LINKSPEED_25G,
    156 	LACP_LINKSPEED_40G,
    157 	LACP_LINKSPEED_50G,
    158 	LACP_LINKSPEED_56G,
    159 	LACP_LINKSPEED_100G,
    160 	LACP_LINKSPEED_200G,
    161 };
    162 
    163 #define LACP_MEDIA_OFFSET	24
    164 #define LACP_MEDIA_MASK		0xff000000U
    165 #define LACP_MEDIA_ETHER	(__BIT(0) << LACP_MEDIA_OFFSET)
    166 #define LACP_MEDIA_FDX		(__BIT(1) << LACP_MEDIA_OFFSET)
    167 #define LACP_MEDIA_DEFAULT	(LACP_LINKSPEED_UNKNOWN |	\
    168 				 LACP_MEDIA_ETHER | LACP_MEDIA_FDX)
    169 #endif
    170