#pragma once #include #include #include #include #include #include #include #include #include #define MR_NODE_CTRLZONE_ID 1 #define MR_NODE_COMMON_MAX_SID_NUM 8 #define MR_NODE_COMMON_VLAN_FLIPPING_DEFAULT_ARG_NUM 2 #define MR_NODE_COMMON_ETHERFABRIC_PKT_OFFSET /* Forward type */ enum { FORWARDER_TYPE_LB = 1, FORWARDER_TYPE_VWIRE, FORWARDER_TYPE_EF, FORWARDER_TYPE_TERA, FORWARDER_TYPE_LAI, FORWARDER_TYPE_HEALTH_CHECK, FORWARDER_TYPE_MAX }; /* Health check for ether type */ enum eth_health_check_type { ETH_HEALTH_CHECK_PRIVATE = 0xAAAA, }; /* Health check remote state */ enum health_check_remote_state { REMOTE_DOWN = 0, REMOTE_UP = 1, }; /* VWire Service Tag */ struct vwire_service_tag { uint8_t dir; uint16_t fwd_table_index; }; struct dev_node_ctx { struct mr_dev_desc * dev_desc; unsigned int last_rxtx_time_in_ms; }; struct mr_generic_ip_hdr { int sa_family; union { const struct rte_ipv4_hdr * ipv4_hdr; const struct rte_ipv6_hdr * ipv6_hdr; }; }; void forwarder_table_insert(uint16_t sid, uint16_t type); #if defined(__x86_64__) static inline void swap_mac_addr(struct rte_ether_hdr * eth_hdr) { /* swap eth_hdr */ __m128i mac_shfl_msk = _mm_set_epi8(15, 14, 13, 12, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6); __m128i mac_addr = _mm_loadu_si128((__m128i *)eth_hdr); mac_addr = _mm_shuffle_epi8(mac_addr, mac_shfl_msk); _mm_storeu_si128((__m128i *)eth_hdr, mac_addr); } #elif defined(__aarch64__) static inline void swap_mac_addr(struct rte_ether_hdr * eth_hdr) { struct rte_ether_addr tmp_addr; rte_ether_addr_copy(ð_hdr->dst_addr, &tmp_addr); rte_ether_addr_copy(ð_hdr->src_addr, ð_hdr->dst_addr); rte_ether_addr_copy(&tmp_addr, ð_hdr->src_addr); } #endif static inline int mr_is_local_addr_for_trunk(struct mr_dev_desc * dev_desc, uint16_t vlan_id, struct mr_generic_ip_hdr * ip_hdr) { assert(dev_desc->dev_mode == MR_DEV_MODE_TRUNK); for (int i = 0; i < dev_desc->nr_vlan_members; i++) { struct vlan_member * vlan_member = &dev_desc->vlan_members[i]; if (vlan_member->vlan_id != vlan_id) { continue; } if (ip_hdr->sa_family == vlan_member->sa_family_v4) { if (vlan_member->in_addr.s_addr == ip_hdr->ipv4_hdr->dst_addr) { return RT_SUCCESS; } } else if (ip_hdr->sa_family == vlan_member->sa_family_v6) { if (memcmp(&vlan_member->in6_addr, &ip_hdr->ipv6_hdr->dst_addr, sizeof(struct in6_addr)) == 0) { return RT_SUCCESS; } } } return RT_ERR; } static inline int mr_is_local_addr(struct mr_dev_desc * dev_desc, struct mr_generic_ip_hdr * ip_hdr) { /* Currently not supporting IPv6 */ if (ip_hdr->sa_family == AF_INET) { if (dev_desc->in_addr.s_addr == ip_hdr->ipv4_hdr->dst_addr) { return RT_SUCCESS; } } return RT_ERR; } #define MR_IS_IPV6_SOLICITED_NODE_MCAST(x) \ (x[0] == 0xFF && x[1] == 0x02 && x[2] == 0x00 && x[3] == 0x00 && x[4] == 0x00 && x[5] == 0x00 && x[6] == 0x00 && \ x[7] == 0x00 && x[8] == 0x00 && x[9] == 0x00 && x[10] == 0x00 && x[11] == 0x01 && x[12] == 0xFF) static inline cJSON * create_uint64_array(const uint64_t * value, unsigned int nr_value) { struct cJSON * uint64_array = cJSON_CreateArray(); for (unsigned int i = 0; i < nr_value; i++) { cJSON_AddItemToArray(uint64_array, cJSON_CreateNumber(value[i])); } return uint64_array; } /***************************************************** Sid handle *****************************************************/ #define SC_SID_HANDLE_CAPACITY_MAX 256 /* Sid handle struct */ struct sid_handle { uint16_t capacity; uint32_t sid_start; uint32_t sid_end; }; struct sid_handle * sid_handle_create(uint32_t sid_start, uint32_t sid_end); int sid_handle_delete(struct sid_handle * sid_handle); uint16_t sid_handle_capacity_get(struct sid_handle * sid_handle); uint32_t sid_handle_sid_start_get(struct sid_handle * sid_handle); uint32_t sid_handle_sid_end_get(struct sid_handle * sid_handle); /******************************************** Network intersection adapter ********************************************/ #define SC_ADAPTERS_MAX 128 int adapters_max_get(struct sc_main * sc, const char * key, uint32_t * adapters_max_out); #define METADATA_INFO \ "dir:%u, nf_create:%u, health_check:%u, is_ctrlbuf:%u, adapter_type:%u, adapter_id:%u, payload_offset:%u, " \ "user_0:%u, ef_link_id:%u, traffic_link_id:%u, ef_peer_index:%u, port_ingress:%u, port_egress:%u, " \ "egress_action:%u, session_id:%lu, cur_sid:%u, sids:%u,%u,%u,%u,%u,%u,%u,%u, measurement_type:%u.\n" void mrb_metadata_pktmbuf_dump(const struct rte_mbuf * m);