/*
* sfe_ipv4.c
* Shortcut forwarding engine - IPv4 edition.
*
* Copyright (c) 2013 Qualcomm Atheros, Inc.
*
* All Rights Reserved.
* Qualcomm Atheros Confidential and Proprietary.
*/
#include <linux/module.h>
#include <linux/sysfs.h>
#include <linux/skbuff.h>
#include <linux/icmp.h>
#include <net/tcp.h>
#include <linux/etherdevice.h>
#include "sfe.h"
#include "sfe_ipv4.h"
/*
* By default Linux IP header and transport layer header structures are
* unpacked, assuming that such headers should be 32-bit aligned.
* Unfortunately some wireless adaptors can't cope with this requirement and
* some CPUs can't handle misaligned accesses. For those platforms we
* define SFE_IPV4_UNALIGNED_IP_HEADER and mark the structures as packed.
* When we do this the compiler will generate slightly worse code than for the
* aligned case (on most platforms) but will be much quicker than fixing
* things up in an unaligned trap handler.
*/
#define SFE_IPV4_UNALIGNED_IP_HEADER 1
#if SFE_IPV4_UNALIGNED_IP_HEADER
#define SFE_IPV4_UNALIGNED_STRUCT __attribute__((packed))
#else
#define SFE_IPV4_UNALIGNED_STRUCT
#endif
/*
* An Ethernet header, but with an optional "packed" attribute to
* help with performance on some platforms (see the definition of
* SFE_IPV4_UNALIGNED_STRUCT)
*/
struct sfe_ipv4_eth_hdr {
__be16 h_dest[ETH_ALEN / 2];
__be16 h_source[ETH_ALEN / 2];
__be16 h_proto;
} SFE_IPV4_UNALIGNED_STRUCT;
/*
* An IPv4 header, but with an optional "packed" attribute to
* help with performance on some platforms (see the definition of
* SFE_IPV4_UNALIGNED_STRUCT)
*/
struct sfe_ipv4_ip_hdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u8 ihl:4,
version:4;
#elif defined (__BIG_ENDIAN_BITFIELD)
__u8 version:4,
ihl:4;
#else
#error "Please fix <asm/byteorder.h>"
#endif
__u8 tos;
__be16 tot_len;
__be16 id;
__be16 frag_off;
__u8 ttl;
__u8 protocol;
__sum16 check;
__be32 saddr;
__be32 daddr;
/*
* The options start here.
*/
} SFE_IPV4_UNALIGNED_STRUCT;
/*
* A UDP header, but with an optional "packed" attribute to
* help with performance on some platforms (see the definition of
* SFE_IPV4_UNALIGNED_STRUCT)
*/
struct sfe_ipv4_udp_hdr {
__be16 source;
__be16 dest;
__be16 len;
__sum16 check;
} SFE_IPV4_UNALIGNED_STRUCT;
/*
* A TCP header, but with an optional "packed" attribute to
* help with performance on some platforms (see the definition of
* SFE_IPV4_UNALIGNED_STRUCT)
*/
struct sfe_ipv4_tcp_hdr {
__be16 source;
__be16 dest;
__be32 seq;
__be32 ack_seq;
#if defined(__LITTLE_ENDIAN_BITFIELD)
__u16 res1:4,
doff:4,
fin:1,
syn:1,
rst:1,
psh:1,
ack:1,
urg:1,
ece:1,
cwr:1;
#elif defined(__BIG_ENDIAN_BITFIELD)
__u16 doff:4,
res1:4,
cwr:1,
ece:1,
urg:1,
ack:1,
psh:1,
rst:1,
syn:1,
fin:1;
#else
#error "Adjust your <asm/byteorder.h> defines"
#endif
__be16 window;
__sum16 check;
__be16 urg_ptr;
} SFE_IPV4_UNALIGNED_STRUCT;
/*
* Specifies the lower bound on ACK numbers carried in the TCP header
*/
#define SFE_IPV4_TCP_MAX_ACK_WINDOW 65520
/*
* IPv4 TCP connection match additional data.
*/
struct sfe_ipv4_tcp_connection_match {
uint8_t win_scale; /* Window scale */
uint32_t max_win; /* Maximum window size seen */
uint32_t end; /* Sequence number of the next byte to send (seq + segment length) */
uint32_t max_end; /* Sequence number of the last byte to ack */
};
/*
* Bit flags for IPv4 connection matching entry.
*/
#define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_SRC 0x1
/* Perform source translation */
#define SFE_IPV4_CONNECTION_MATCH_FLAG_XLATE_DEST 0x2
/* Perform destination translation */
#define SFE_IPV4_CONNECTION_MATCH_FLAG_NO_SEQ_CHECK 0x4
/* Ignore TCP sequence numbers */
#define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_FAST_ETH_HDR 0x8
/* Fast Ethernet header write */
#define SFE_IPV4_CONNECTION_MATCH_FLAG_WRITE_L2_HDR 0x10
/* Fast Ethernet header write */
/*
* IPv4 connection matching structure.
*/
struct sfe_ipv4_connection_match {
/*
* References to other objects.
*/
struct sfe_ipv4_connection_match *next;
/* Next connection match entry in a list */
struct sfe_ipv4_connection_match *prev;
/* Previous connection match entry in a list */
struct sfe_ipv4_connection *connection;
/* Pointer to our connection */
struct sfe_ipv4_connection_match *counter_match;
/* Pointer to the connection match in the "counter" direction to this one */
struct sfe_ipv4_connection_match *active_next;
/* Pointer to the next connection in the active list */
struct sfe_ipv4_connection_match *active_prev;
/* Pointer to the previous connection in the active list */
bool active; /* Flag to indicate if we're on the active list */
/*
* Characteristics that identify flows that match this rule.
*/
struct net_device *match_dev; /* Network device */
uint8_t match_protocol; /* Protocol */
__be32 match_src_ip; /* Source IP address */
__be32 match_dest_ip; /* Destination IP address */
__be16 match_src_port; /* Source port/connection ident */
__be16 match_dest_port; /* Destination port/connection ident */
/*
* Control the operations of the match.
*/
uint32_t flags; /* Bit flags */
/*
* Connection state that we track once we match.
*/
union { /* Protocol-specific state */
struct sfe_ipv4_tcp_connection_match tcp;
} protocol_state;
uint32_t rx_packet_count; /* Number of packets RX'd */
uint32_t rx_byte_count; /* Number of bytes RX'd */
/*
* Packet translation information.
*/
__be32 xlate_src_ip; /* Address after source translation */
__be16 xlate_src_port; /* Port/connection ident after source translation */
uint16_t xlate_src_csum_adjustment;
/* Transport layer checksum adjustment after source translation */
__be32 xlate_dest_ip; /* Address after destination translation */
__be16 xlate_dest_port; /* Port/connection ident after destination translation */
uint16_t xlate_dest_csum_adjustment;
/* Transport layer checksum adjustment after destination translation */
/*
* Packet transmit information.
*/
struct net_device *xmit_dev; /* Network device on which to transmit */
unsigned short int xmit_dev_mtu;
/* Interface MTU */
uint16_t xmit_dest_mac[ETH_ALEN / 2];
/* Destination MAC address to use when forwarding */
uint16_t xmit_src_mac[ETH_ALEN / 2];
/* Source MAC address to use when forwarding */
/*
* Summary stats.
*/
uint64_t rx_packet_count64; /* Number of packets RX'd */
uint64_t rx_byte_count64; /* Number of bytes RX'd */
};
/*
* Per-connection data structure.
*/
struct sfe_ipv4_connection {
struct sfe_ipv4_connection *next;
/* Pointer to the next entry in a hash chain */
struct sfe_ipv4_connection *prev;
/* Pointer to the previous entry in a hash chain */
int protocol; /* IP protocol number */
__be32 src_ip; /* Source IP address */
__be32 src_ip_xlate; /* NAT-translated source IP address */
__be32 dest_ip; /* Destination IP address */
__be32 dest_ip_xlate; /* NAT-translated destination IP address */
__be16 src_port; /* Source port */
__be16 src_port_xlate; /* NAT-translated source port */
__be16 dest_port; /* Destination port */
__be16 dest_port_xlate; /* NAT-translated destination port */
struct sfe_ipv4_connection_match *original_match;
/* Original direction matching structure */
struct net_device *original_dev;
/* Original direction source device */
struct sfe_ipv4_connection_match *reply_match;
/* Reply direction matching structure */
struct net_device *reply_dev; /* Reply direction source device */
uint64_t last_sync_jiffies; /* Jiffies count for the last sync */
struct sfe_ipv4_connection *all_connections_next;
/* Pointer to the next entry in the list of all connections */
struct sfe_ipv4_connection *all_connections_prev;
/* Pointer to the previous entry in the list of all c
qsdk-qca-shortcut-fe-2.7.029.zip_qca sdk_qca-wifi_qsdk_qsdk 驱动目
版权申诉
156 浏览量
2022-09-23
17:28:58
上传
评论
收藏 32KB ZIP 举报
JonSco
- 粉丝: 67
- 资源: 1万+
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0