|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | +// Copyright (c) 2025 Robin Jarry |
| 3 | + |
| 4 | +#pragma once |
| 5 | + |
| 6 | +#include <gr_bitops.h> |
| 7 | + |
| 8 | +#include <rte_ether.h> |
| 9 | + |
| 10 | +#include <stdint.h> |
| 11 | + |
| 12 | +// Slow Protocol Subtypes |
| 13 | +typedef enum : uint8_t { |
| 14 | + LACP_SUBTYPE = 1, |
| 15 | +} slow_subtype_t; |
| 16 | + |
| 17 | +// LACP Version |
| 18 | + |
| 19 | +typedef enum : uint8_t { |
| 20 | + LACP_VERSION_1 = 1, |
| 21 | +} lacp_version_t; |
| 22 | + |
| 23 | +// LACP TLV Types |
| 24 | +typedef enum : uint8_t { |
| 25 | + LACP_TYPE_ACTOR = 1, |
| 26 | + LACP_TYPE_PARTNER = 2, |
| 27 | + LACP_TYPE_COLLECTOR = 3, |
| 28 | + LACP_TYPE_TERMINATOR = 0, |
| 29 | +} lacp_type_t; |
| 30 | + |
| 31 | +#define LACP_LEN_ACTOR 20 |
| 32 | +#define LACP_LEN_PARTNER 20 |
| 33 | +#define LACP_LEN_COLLECTOR 16 |
| 34 | +#define LACP_LEN_TERMINATOR 0 |
| 35 | + |
| 36 | +// LACP State Bits |
| 37 | +typedef enum : uint8_t { |
| 38 | + // If set, will spontaneously send LACP packets, else will |
| 39 | + // only do so when receiving LACP packets from a peer. |
| 40 | + LACP_STATE_ACTIVE = GR_BIT8(0), |
| 41 | + // If set, LACP_FAST_PERIOD and LACP_SHORT_TIMEOUT, |
| 42 | + // else LACP_SLOW_PERIOD and LACP_LONG_TIMEOUT. |
| 43 | + LACP_STATE_FAST = GR_BIT8(1), |
| 44 | + // The link is part of a bond. |
| 45 | + LACP_STATE_AGGREGATABLE = GR_BIT8(2), |
| 46 | + // System ID and key are in sync. |
| 47 | + LACP_STATE_SYNCHRONIZED = GR_BIT8(3), |
| 48 | + // Collecting indicates that the participant’s collector (the receive part |
| 49 | + // of the mux) is on. If set, it communicates Collecting. |
| 50 | + LACP_STATE_COLLECTING = GR_BIT8(4), |
| 51 | + // Distributing indicates that the participant’s distributor (the transmit part |
| 52 | + // of the mux) is not definitely off. If reset, it indicates Not Distributing. |
| 53 | + LACP_STATE_DISTRIBUTING = GR_BIT8(5), |
| 54 | + LACP_STATE_DEFAULTED = GR_BIT8(6), |
| 55 | + LACP_STATE_EXPIRED = GR_BIT8(7), |
| 56 | +} lacp_state_flags_t; |
| 57 | + |
| 58 | +// LACP Timeouts (in seconds) |
| 59 | +#define LACP_FAST_PERIOD 1 |
| 60 | +#define LACP_SLOW_PERIOD 30 |
| 61 | +#define LACP_SHORT_TIMEOUT 3 |
| 62 | +#define LACP_LONG_TIMEOUT 90 |
| 63 | + |
| 64 | +struct lacp_participant { |
| 65 | + rte_be16_t system_priority; |
| 66 | + struct rte_ether_addr system_mac; |
| 67 | + rte_be16_t key; |
| 68 | + rte_be16_t port_priority; |
| 69 | + rte_be16_t port_number; |
| 70 | + lacp_state_flags_t state; |
| 71 | + uint8_t __padding[3]; |
| 72 | +} __rte_packed __rte_aligned(2); |
| 73 | + |
| 74 | +struct lacp_pdu { |
| 75 | + slow_subtype_t subtype; // LACP_SUBTYPE |
| 76 | + lacp_version_t version; // LACP_VERSION_1 |
| 77 | + |
| 78 | + // Actor Information |
| 79 | + lacp_type_t actor_type; // LACP_TYPE_ACTOR |
| 80 | + uint8_t actor_len; // LACP_LEN_ACTOR |
| 81 | + struct lacp_participant actor; |
| 82 | + |
| 83 | + // Partner Information |
| 84 | + lacp_type_t partner_type; // LACP_TYPE_PARTNER |
| 85 | + uint8_t partner_len; // LACP_LEN_PARTNER |
| 86 | + struct lacp_participant partner; |
| 87 | + |
| 88 | + // Collector Information |
| 89 | + lacp_type_t collector_type; // LACP_TYPE_COLLECTOR |
| 90 | + uint8_t collector_len; // LACP_LEN_COLLECTOR |
| 91 | + rte_be16_t collector_max_delay; |
| 92 | + uint8_t __reserved[12]; |
| 93 | + |
| 94 | + // Terminator |
| 95 | + lacp_type_t terminator_type; // LACP_TYPE_TERMINATOR |
| 96 | + uint8_t terminator_len; // LACP_LEN_TERMINATOR |
| 97 | + uint8_t __padding[50]; // Pad to minimum frame size |
| 98 | +} __rte_packed __rte_aligned(2); |
0 commit comments