Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switchlink header file cleanup #85

Merged
merged 10 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions switchlink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CMake build file for krnlmon/switchlink
#
# Copyright 2022-2023 Intel Corporation
# Copyright 2022-2024 Intel Corporation
# SPDX-License-Identifier: Apache 2.0

include(FindGTest)
Expand All @@ -15,10 +15,11 @@ add_library(switchlink_o OBJECT
switchlink_db_int.h
switchlink.h
switchlink_globals.c
switchlink_handle.h
switchlink_globals.h
switchlink_handlers.h
switchlink_int.h
switchlink_link.c
switchlink_link.h
switchlink_link_types.h
switchlink_main.c
switchlink_main.h
switchlink_neigh.c
Expand Down
5 changes: 3 additions & 2 deletions switchlink/sai/switchlink_handle_ecmp.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +16,7 @@
* limitations under the License.
*/

#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_handlers.h"
#include "switchlink_init_sai.h"

static sai_next_hop_group_api_t* sai_nhop_group_api = NULL;
Expand Down
3 changes: 2 additions & 1 deletion switchlink/sai/switchlink_handle_lag.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2023 Intel Corporation.
* Copyright 2023-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions switchlink/sai/switchlink_handle_link.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +16,7 @@
* limitations under the License.
*/

#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_handlers.h"
#include "switchlink_init_sai.h"

static sai_virtual_router_api_t* sai_vrf_api = NULL;
Expand Down
9 changes: 6 additions & 3 deletions switchlink/sai/switchlink_handle_neigh.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,11 +16,13 @@
* limitations under the License.
*/

#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_globals.h"
#include "switchlink/switchlink_handlers.h"
#include "switchlink_init_sai.h"

static sai_neighbor_api_t* sai_neigh_api = NULL;
static sai_fdb_api_t* sai_fdb_api = NULL;

/*
* Routine Description:
* Initialize Neighbor SAI API
Expand Down Expand Up @@ -71,7 +74,7 @@ sai_status_t sai_init_fdb_api() {
*/

bool validate_delete_nexthop(uint32_t using_by,
switchlink_nhop_using_by_e type) {
enum switchlink_nhop_using_by type) {
return (using_by & ~(type)) ? false : true;
}

Expand Down
5 changes: 3 additions & 2 deletions switchlink/sai/switchlink_handle_nexthop.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +16,7 @@
* limitations under the License.
*/

#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_handlers.h"
#include "switchlink_init_sai.h"

static sai_next_hop_api_t* sai_nhop_api = NULL;
Expand Down
6 changes: 4 additions & 2 deletions switchlink/sai/switchlink_handle_route.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +16,8 @@
* limitations under the License.
*/

#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_globals.h"
#include "switchlink/switchlink_handlers.h"
#include "switchlink_init_sai.h"

static sai_route_api_t* sai_route_api = NULL;
Expand Down
5 changes: 3 additions & 2 deletions switchlink/sai/switchlink_handle_tunnel.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +16,7 @@
* limitations under the License.
*/

#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_handlers.h"
#include "switchlink_init_sai.h"

static sai_tunnel_api_t* sai_tunnel_intf_api = NULL;
Expand Down
2 changes: 1 addition & 1 deletion switchlink/sai/switchlink_init_sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ int switchlink_create_vrf(switchlink_handle_t* vrf_h);

// General utility function
bool validate_delete_nexthop(uint32_t using_by,
switchlink_nhop_using_by_e type);
enum switchlink_nhop_using_by type);

#endif /* __SWITCHLINK_INIT_SAI_H__ */
28 changes: 6 additions & 22 deletions switchlink/switchlink.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,15 +27,12 @@
#define switchlink_malloc(x, c) malloc((x) * (c))
#define switchlink_free(x) free(x)

#define SWITCHLINK_LOG_ERR 1
#define SWITCHLINK_LOG_WARN 2
#define SWITCHLINK_LOG_INFO 3
#define SWITCHLINK_LOG_DEBUG 4

#define SWITCH_LINK_INVALID_HANDLE 0x0

typedef uint64_t switchlink_handle_t;

typedef uint8_t switchlink_mac_addr_t[6];

typedef struct switchlink_ip_addr_ {
uint8_t family;
uint8_t prefix_len;
Expand All @@ -44,24 +42,10 @@ typedef struct switchlink_ip_addr_ {
} ip;
} switchlink_ip_addr_t;

extern uint8_t g_log_level;
extern switchlink_handle_t g_default_vrf_h;
extern switchlink_handle_t g_default_bridge_h;
extern switchlink_handle_t g_cpu_rx_nhop_h;

struct nl_sock* switchlink_get_nl_sock(void);

typedef enum switchlink_entry_type {
SWITCHLINK_FDB_NONE = 0,
SWITCHLINK_FDB_ADD = 1,
SWITCHLINK_FDB_DEL = 2,
SWITCHLINK_FDB_MAX = 3,
} switchlink_entry_type_e;

typedef enum switchlink_nhop_using_by {
enum switchlink_nhop_using_by {
SWITCHLINK_NHOP_FROM_NONE = 0,
SWITCHLINK_NHOP_FROM_NEIGHBOR = 1 << 0,
SWITCHLINK_NHOP_FROM_ROUTE = 1 << 1,
} switchlink_nhop_using_by_e;
};

#endif /* __SWITCHLINK_H__ */
7 changes: 3 additions & 4 deletions switchlink/switchlink_address.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
*
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,9 +18,9 @@

#include <netlink/msg.h>

#include "switchlink_handle.h"
#include "switchlink_globals.h"
#include "switchlink_handlers.h"
#include "switchlink_int.h"
#include "switchlink_route.h"

/*
* Routine Description:
Expand Down
9 changes: 6 additions & 3 deletions switchlink/switchlink_address_test.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2023-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include <arpa/inet.h>
#include <linux/if_arp.h>
#include <memory.h>
Expand All @@ -8,9 +11,9 @@
#include "gtest/gtest.h"

extern "C" {
#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_int.h"
#include "switchlink/switchlink_route.h"
#include "switchlink_handlers.h"
#include "switchlink_int.h"
#include "switchlink_route.h"
}

using namespace std;
Expand Down
7 changes: 3 additions & 4 deletions switchlink/switchlink_db.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,9 +26,7 @@
#include "switchlink.h"
#include "switchlink_db_int.h"
#include "switchlink_int.h"
#include "switchlink_link.h"
#include "switchlink_neigh.h"
#include "switchlink_route.h"
#include "switchlink_link_types.h"
#include "xxHash/xxhash.h"

#define SWITCHLINK_MAC_KEY_LEN 14
Expand Down
5 changes: 3 additions & 2 deletions switchlink/switchlink_db.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +22,7 @@
#include <stdbool.h>

#include "switchlink.h"
#include "switchlink_link.h"
#include "switchlink_link_types.h"

#define SWITCHLINK_INTERFACE_NAME_LEN_MAX 32
#define SWITCHLINK_ECMP_NUM_MEMBERS_MAX 16
Expand Down
2 changes: 1 addition & 1 deletion switchlink/switchlink_globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache 2.0
*/

#include "switchlink.h"
#include "switchlink_globals.h"

switchlink_handle_t g_default_vrf_h = 0;
switchlink_handle_t g_default_bridge_h = 0;
Expand Down
16 changes: 16 additions & 0 deletions switchlink/switchlink_globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*/

#ifndef __SWITCHLINK_GLOBALS_H__
#define __SWITCHLINK_GLOBALS_H__

#include "switchlink.h"

extern switchlink_handle_t g_default_vrf_h;
extern switchlink_handle_t g_default_bridge_h;
extern switchlink_handle_t g_cpu_rx_nhop_h;

#endif /* __SWITCHLINK_GLOBALS_H__ */
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
* Copyright 2022-2024 Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
* limitations under the License.
*/

#ifndef __SWITCHLINK_HANDLE_H__
#define __SWITCHLINK_HANDLE_H__
#ifndef __SWITCHLINK_HANDLERS_H__
#define __SWITCHLINK_HANDLERS_H__

#include <stdbool.h>
#include <stdint.h>
Expand Down Expand Up @@ -81,6 +81,6 @@ extern int switchlink_create_vrf(switchlink_handle_t* vrf_h);

// General utility function
extern bool validate_delete_nexthop(uint32_t using_by,
switchlink_nhop_using_by_e type);
enum switchlink_nhop_using_by type);

#endif /* __SWITCHLINK_HANDLE_H__ */
#endif /* __SWITCHLINK_HANDLERS_H__ */
9 changes: 4 additions & 5 deletions switchlink/switchlink_link.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright 2022-2023 Intel Corporation.
*
* Copyright 2022-2024 Intel Corporation.
* SPDX-License-Identifier: Apache 2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,8 +16,6 @@
* limitations under the License.
*/

#include "switchlink_link.h"

#include <fcntl.h>
#include <linux/errno.h>
#include <linux/ethtool.h>
Expand All @@ -33,8 +30,10 @@
#include <unistd.h>

#include "switchlink.h"
#include "switchlink_handle.h"
#include "switchlink_globals.h"
#include "switchlink_handlers.h"
#include "switchlink_int.h"
#include "switchlink_link_types.h"
#include "switchlink_utils.h"

#if defined(ES2K_TARGET)
Expand Down
9 changes: 5 additions & 4 deletions switchlink/switchlink_link_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Intel Corporation
// Copyright 2023-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include <linux/if_arp.h>
Expand All @@ -10,9 +10,10 @@
#include "gtest/gtest.h"

extern "C" {
#include "switchlink/switchlink_handle.h"
#include "switchlink/switchlink_int.h"
#include "switchlink/switchlink_link.h"
#include "switchlink_globals.h"
#include "switchlink_handlers.h"
#include "switchlink_int.h"
#include "switchlink_link_types.h"
}

#define IPV4_ADDR(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
Expand Down
File renamed without changes.
Loading