TSG-13347 Steering Service开发流表

This commit is contained in:
luwenpeng
2023-01-10 16:30:34 +08:00
parent 4639d9ceaa
commit fcc99918fd
13 changed files with 466 additions and 63 deletions

View File

@@ -1,30 +0,0 @@
#ifndef _CONNTABLE_H
#define _CONNTABLE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
struct tuple4
{
/* data */
};
struct conntable;
struct conntable *conntable_create();
void conntable_destory(struct conntable *table);
void conntable_add(struct conntable *table, uint64_t streamid, void *val);
void conntable_del(struct conntable *table, uint64_t streamid);
void *conntable_search_by_streamid(struct conntable *table, uint64_t streamid);
void *conntable_search_by_tuple4(struct conntable *table, struct tuple4 *tuplekey);
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -0,0 +1,49 @@
#ifndef _STREAM_ADDR_H
#define _STREAM_ADDR_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <netinet/in.h>
enum stream_addr_type
{
STREAM_ADDR_TYPE_V4,
STREAM_ADDR_TYPE_V6,
};
struct stream_addr_v4
{
struct in_addr src_addr; /* network order */
struct in_addr dst_addr; /* network order */
in_port_t src_port; /* network order */
in_port_t dst_port; /* network order */
};
struct stream_addr_v6
{
struct in6_addr src_addr; /* network order */
struct in6_addr dst_addr; /* network order */
in_port_t src_port; /* network order */
in_port_t dst_port; /* network order */
};
struct stream_addr
{
enum stream_addr_type addr_type;
union
{
struct stream_addr_v4 addr_v4;
struct stream_addr_v6 addr_v6;
};
};
char *stream_addr_to_str(const struct stream_addr *addr);
#ifdef __cpluscplus
}
#endif
#endif

View File

@@ -0,0 +1,50 @@
#ifndef _STREAM_TABLE_H
#define _STREAM_TABLE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
#include <sys/types.h>
#include "uthash.h"
#include "stream_addr.h"
// Note: key_streamaddr must be initialized by memset(0) before use !!!
typedef void fn_free_cb(void *args);
struct stream_node
{
uint64_t key_streamid; /* first key */
struct stream_addr key_streamaddr; /* second key */
void *val_data;
fn_free_cb *val_freecb;
UT_hash_handle hh1; /* handle for first hash table */
UT_hash_handle hh2; /* handle for second hash table */
};
struct stream_table;
struct stream_table *stream_table_create();
void stream_table_destory(struct stream_table *table);
// key_streamaddr : deep copy
// val_data : shallow copy (malloc by user, free by val_freecb)
int stream_table_insert(struct stream_table *table, uint64_t key_streamid, const struct stream_addr *key_streamaddr, void *val_data, const fn_free_cb *val_freecb);
int stream_table_delete_by_streamid(struct stream_table *table, uint64_t key_streamid);
int stream_table_delete_by_streamaddr(struct stream_table *table, const struct stream_addr *key_streamaddr);
struct stream_node *stream_table_search_by_streamid(struct stream_table *table, uint64_t key_streamid);
struct stream_node *stream_table_search_by_streamaddr(struct stream_table *table, const struct stream_addr *key_streamaddr);
#ifdef __cpluscplus
}
#endif
#endif