1 /* $NetBSD: if_lagg_lacp.h,v 1.5 2023/11/22 03:49:13 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 #define LACP_SENDDU_PPS 3 45 #define LACP_RCVDU_LIMIT (LACP_SENDDU_PPS * LACP_MAX_PORTS) 46 47 #define LACP_PARTNER_ADMIN_OPTIMISTIC (LACP_STATE_SYNC | \ 48 LACP_STATE_AGGREGATION | \ 49 LACP_STATE_COLLECTING | \ 50 LACP_STATE_DISTRIBUTING) 51 #define LACP_PARTNER_ADMIN_STRICT 0 52 53 #define TLV_TYPE_TERMINATE 0 54 55 #define LACP_TYPE_TERMINATE TLV_TYPE_TERMINATE 56 #define LACP_TYPE_ACTORINFO 1 57 #define LACP_TYPE_PARTNERINFO 2 58 #define LACP_TYPE_COLLECTORINFO 3 59 60 #define MARKER_TYPE_TERMINATE TLV_TYPE_TERMINATE 61 #define MARKER_TYPE_INFO 1 62 #define MARKER_TYPE_RESPONSE 2 63 64 struct tlvhdr { 65 uint8_t tlv_type; 66 uint8_t tlv_length; 67 } __packed; 68 69 struct tlv { 70 uint8_t tlv_t; 71 uint8_t tlv_l; 72 void *tlv_v; 73 }; 74 75 static inline void 76 tlv_set(struct tlvhdr *th, uint8_t t, uint8_t l) 77 { 78 79 th->tlv_type = t; 80 th->tlv_length = sizeof(*th) + l; 81 } 82 83 struct lacpdu_peerinfo { 84 uint16_t lpi_system_prio; 85 uint8_t lpi_system_mac[LACP_MAC_LEN]; 86 uint16_t lpi_key; 87 uint16_t lpi_port_prio; 88 uint16_t lpi_port_no; 89 uint8_t lpi_state; 90 uint8_t lpi_resv[3]; 91 } __packed; 92 93 struct lacpdu_collectorinfo { 94 uint16_t lci_maxdelay; 95 uint8_t lci_resv[12]; 96 } __packed; 97 98 struct lacpdu { 99 struct ether_header ldu_eh; 100 struct slowprothdr ldu_sph; 101 102 struct tlvhdr ldu_tlv_actor; 103 struct lacpdu_peerinfo ldu_actor; 104 struct tlvhdr ldu_tlv_partner; 105 struct lacpdu_peerinfo ldu_partner; 106 107 struct tlvhdr ldu_tlv_collector; 108 struct lacpdu_collectorinfo 109 ldu_collector; 110 111 struct tlvhdr ldu_tlv_term; 112 uint8_t ldu_resv[50]; 113 } __packed; 114 115 struct markerdu_info { 116 uint16_t mi_rq_port; 117 uint8_t mi_rq_system[LACP_MAC_LEN]; 118 uint32_t mi_rq_xid; 119 uint8_t mi_pad[2]; 120 } __packed; 121 122 struct markerdu { 123 struct ether_header mdu_eh; 124 struct slowprothdr mdu_sph; 125 126 struct tlvhdr mdu_tlv_info; 127 struct markerdu_info mdu_info; 128 129 struct tlvhdr mdu_tlv_term; 130 uint8_t mdu_resv[90]; 131 } __packed; 132 #endif 133