TSG-7784 PacketAdapter支持CI自动构建RPM; 修改代码结构
This commit is contained in:
36
common/include/decode_gtp.h
Normal file
36
common/include/decode_gtp.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _DECODE_GTP_H
|
||||
#define _DECODE_GTP_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "public.h"
|
||||
|
||||
/* According to 3GPP TS 29.060. */
|
||||
typedef struct gtp1_header_s
|
||||
{
|
||||
uint8_t flags;
|
||||
uint8_t type;
|
||||
uint16_t length;
|
||||
uint32_t tid;
|
||||
} __attribute__((packed)) gtp1_header_t;
|
||||
|
||||
typedef struct gtp_info_s
|
||||
{
|
||||
gtp1_header_t *hdr;
|
||||
uint8_t *payload;
|
||||
|
||||
uint32_t hdr_len;
|
||||
uint32_t payload_len;
|
||||
} gtp_info_t;
|
||||
|
||||
int decode_gtp(gtp_info_t *packet, const uint8_t *data, uint32_t len);
|
||||
void dump_gtp_info(uint32_t pkt_id, gtp_info_t *packet);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
55
common/include/decode_ipv4.h
Normal file
55
common/include/decode_ipv4.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef _DECODE_IPV4_H
|
||||
#define _DECODE_IPV4_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "public.h"
|
||||
|
||||
#define IPV4_HEADER_LEN 20
|
||||
|
||||
typedef struct ipv4_header_s
|
||||
{
|
||||
uint8_t ip_verhl; // version & header length
|
||||
uint8_t ip_tos;
|
||||
uint16_t ip_len;
|
||||
uint16_t ip_id;
|
||||
uint16_t ip_off;
|
||||
uint8_t ip_ttl;
|
||||
uint8_t ip_proto;
|
||||
uint16_t ip_csum;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
struct in_addr ip_src;
|
||||
struct in_addr ip_dst;
|
||||
} ip4_un1;
|
||||
uint16_t ip_addrs[4];
|
||||
} ip4_hdrun1;
|
||||
} __attribute__((__packed__)) ipv4_header_t;
|
||||
|
||||
typedef struct ipv4_info_s
|
||||
{
|
||||
char src_addr[INET_ADDRSTRLEN];
|
||||
char dst_addr[INET_ADDRSTRLEN];
|
||||
|
||||
ipv4_header_t *hdr;
|
||||
uint8_t *payload;
|
||||
uint8_t next_protocol;
|
||||
|
||||
uint32_t hdr_len;
|
||||
uint32_t opts_len;
|
||||
uint32_t payload_len;
|
||||
} ipv4_info_t;
|
||||
|
||||
int decode_ipv4(ipv4_info_t *packet, const uint8_t *data, uint32_t len);
|
||||
void dump_ipv4_info(uint32_t pkt_id, ipv4_info_t *packet);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
58
common/include/decode_ipv6.h
Normal file
58
common/include/decode_ipv6.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef _DECODE_IPV6_H
|
||||
#define _DECODE_IPV6_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "public.h"
|
||||
|
||||
#define IPV6_HEADER_LEN 40
|
||||
|
||||
typedef struct ipv6_header_s
|
||||
{
|
||||
union
|
||||
{
|
||||
struct ip6_un1_
|
||||
{
|
||||
uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
|
||||
uint16_t ip6_un1_plen; /* payload length */
|
||||
uint8_t ip6_un1_nxt; /* next header */
|
||||
uint8_t ip6_un1_hlim; /* hop limit */
|
||||
} ip6_un1;
|
||||
uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
|
||||
} ip6_hdrun;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint32_t ip6_src[4];
|
||||
uint32_t ip6_dst[4];
|
||||
} ip6_un2;
|
||||
uint16_t ip6_addrs[16];
|
||||
} ip6_hdrun2;
|
||||
} __attribute__((__packed__)) ipv6_header_t;
|
||||
|
||||
typedef struct ipv6_info_s
|
||||
{
|
||||
char src_addr[INET6_ADDRSTRLEN];
|
||||
char dst_addr[INET6_ADDRSTRLEN];
|
||||
|
||||
ipv6_header_t *hdr;
|
||||
uint8_t *payload;
|
||||
uint8_t next_protocol;
|
||||
|
||||
uint32_t hdr_len;
|
||||
uint32_t payload_len;
|
||||
} ipv6_info_t;
|
||||
|
||||
int decode_ipv6(ipv6_info_t *packet, const uint8_t *data, uint32_t len);
|
||||
void dump_ipv6_info(uint32_t pkt_id, ipv6_info_t *packet);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
46
common/include/decode_tcp.h
Normal file
46
common/include/decode_tcp.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef _DECODE_TCP_H
|
||||
#define _DECODE_TCP_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "public.h"
|
||||
|
||||
#define TCP_HEADER_LEN 20
|
||||
|
||||
typedef struct tcp_header_s
|
||||
{
|
||||
uint16_t th_sport; /**< source port */
|
||||
uint16_t th_dport; /**< destination port */
|
||||
uint32_t th_seq; /**< sequence number */
|
||||
uint32_t th_ack; /**< acknowledgement number */
|
||||
uint8_t th_offx2; /**< offset and reserved */
|
||||
uint8_t th_flags; /**< pkt flags */
|
||||
uint16_t th_win; /**< pkt window */
|
||||
uint16_t th_sum; /**< checksum */
|
||||
uint16_t th_urp; /**< urgent pointer */
|
||||
} __attribute__((__packed__)) tcp_header_t;
|
||||
|
||||
typedef struct tcp_info_s
|
||||
{
|
||||
uint16_t src_port;
|
||||
uint16_t dst_port;
|
||||
|
||||
tcp_header_t *hdr;
|
||||
uint8_t *payload;
|
||||
|
||||
uint32_t opt_len;
|
||||
uint32_t hdr_len;
|
||||
uint32_t payload_len;
|
||||
} tcp_info_t;
|
||||
|
||||
int decode_tcp(tcp_info_t *packet, const uint8_t *data, uint32_t len);
|
||||
void dump_tcp_info(uint32_t pkt_id, tcp_info_t *packet);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
40
common/include/decode_udp.h
Normal file
40
common/include/decode_udp.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef _DECODE_UDP_H
|
||||
#define _DECODE_UDP_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "public.h"
|
||||
|
||||
#define UDP_HEADER_LEN 8
|
||||
|
||||
typedef struct udp_header_s
|
||||
{
|
||||
uint16_t udp_src_port;
|
||||
uint16_t udp_dst_port;
|
||||
uint16_t udp_len;
|
||||
uint16_t udp_sum;
|
||||
} __attribute__((__packed__)) udp_header_t;
|
||||
|
||||
typedef struct udp_info_s
|
||||
{
|
||||
uint16_t src_port;
|
||||
uint16_t dst_port;
|
||||
|
||||
udp_header_t *hdr;
|
||||
uint8_t *payload;
|
||||
|
||||
uint32_t hdr_len;
|
||||
uint32_t payload_len;
|
||||
} udp_info_t;
|
||||
|
||||
int decode_udp(udp_info_t *packet, const uint8_t *data, uint32_t len);
|
||||
void dump_udp_info(uint32_t pkt_id, udp_info_t *packet);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
41
common/include/public.h
Normal file
41
common/include/public.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _PUBLIC_H
|
||||
#define _PUBLIC_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define IP_GET_RAW_VER(raw_pkt) ((((raw_pkt)[0] & 0xf0) >> 4))
|
||||
|
||||
#define PRINT_FILE_INFO 0
|
||||
|
||||
#if (PRINT_FILE_INFO)
|
||||
#define LOG_DEBUG(format, ...) \
|
||||
fprintf(stdout, "[%s-%s()-%05d] " format "\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
|
||||
|
||||
#define LOG_ERROR(format, ...) \
|
||||
fprintf(stderr, "[%s-%s()-%05d] " format "\n", __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
|
||||
#else
|
||||
#define LOG_DEBUG(format, ...) \
|
||||
fprintf(stdout, format "\n", ##__VA_ARGS__);
|
||||
|
||||
#define LOG_ERROR(format, ...) \
|
||||
fprintf(stderr, format "\n", ##__VA_ARGS__);
|
||||
#endif
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user