Bill Fischofer(Bill-Fischofer-Linaro) replied on github web page: example/ipsec_offload/odp_ipsec_offload_fwd_db.h line 96 @@ -0,0 +1,201 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_IPSEC_FWD_DB_H_ +#define ODP_IPSEC_FWD_DB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <odp.h> +#include <odp/helper/eth.h> +#include <odp_ipsec_offload_misc.h> + +#define OIF_LEN 32 + +/** + * Forwarding data base entry + */ + +typedef struct fwd_db_entry_s { + struct fwd_db_entry_s *next; /**< Next entry on list */ + char oif[OIF_LEN]; /**< Output interface name */ + odp_pktout_queue_t pktout; /**< Output transmit queue */ + uint8_t src_mac[ODPH_ETHADDR_LEN]; /**< Output source MAC */ + uint8_t dst_mac[ODPH_ETHADDR_LEN]; /**< Output destination MAC */ + ip_addr_range_t subnet; /**< Subnet for this router */ +} fwd_db_entry_t; + +/** + * Forwarding data base global structure + */ +typedef struct fwd_db_s { + uint32_t index; /**< Next available entry */ + fwd_db_entry_t *list; /**< List of active routes */ + fwd_db_entry_t array[MAX_DB]; /**< Entry storage */ +} fwd_db_t; + +/** Global pointer to fwd db */ +extern fwd_db_t *fwd_db; + +/** + * Flow cache table entry + */ +typedef struct { + void *next; /**< Pointer to next flow in list*/ + uint32_t l3_src; /**< Source IP Address*/ + uint32_t l3_dst; /**< Destination IP Address*/ + odp_out_entry_t out_port; /**< Out interface of matching flow*/ +} odp_flow_entry_t; + +/** + * Flow cache table bucket + */ +typedef struct { + odp_spinlock_t lock; /**< Bucket lock*/ + odp_flow_entry_t *next; /**< Pointer to first flow entry in bucket*/ +} flow_bucket_t; + +/** +* Pointers to Flow cache tables +*/ +extern flow_bucket_t *flow_table; + +extern flow_bucket_t *ipsec_out_flow_table; + +extern flow_bucket_t *ipsec_in_flow_table; + +/** + * Number of buckets in hash table + */ +extern uint32_t bucket_count; + +/* + * Allocate and Initialize routing table with default Route entries. + * + */ +void odp_init_routing_table(void); + +/* + * Searches flow entry in given hash bucket according to given 5-tuple + * information + * + * @param sip Source IP Address + * @param dip Destination IP Address + * @param sport Source Port Number + * @param dport Destination Port Number + * @param proto IP protocol + * @param bucket Hash Bucket + * + * @return Matching flow entry + */ +static inline odp_flow_entry_t *odp_route_flow_lookup_in_bucket(uint32_t sip,
Comment: Drop `odp_` prefix > Bill Fischofer(Bill-Fischofer-Linaro) wrote: > Avoid `odp_` prefix use for non-APIs. >> Bill Fischofer(Bill-Fischofer-Linaro) wrote: >> Checkpatch doesn't like this and the `goto` is a bit ugly. Might a >> restructure along the following lines be simpler and cleaner? >> ``` >> if (!flow) { >> /*Check into Routing table*/ >> fwd_entry = find_fwd_db_entry(dip); >> >> if (!fwd_entry) { >> EXAMPLE_DBG("No flow match found. Packet is >> dropped.\n"); >> odp_packet_free(pkt); >> return PKT_DROP; >> } >> ... flow setup processing, fall though without needing a goto. >> } >> >> ...flow processing goes here >> ``` >>> Bill Fischofer(Bill-Fischofer-Linaro) wrote: >>> Drop the `odp_` prefix here. It's reserved for ODP APIs. >>>> Bill Fischofer(Bill-Fischofer-Linaro) wrote: >>>> Don't use the `odp_` prefix for application routines. It's not a good >>>> practice, especially in an example. https://github.com/Linaro/odp/pull/339#discussion_r157375390 updated_at 2017-12-17 18:09:28