perf: Reduce str_to_mac() and inet_addr() calls

This commit is contained in:
luwenpeng
2023-10-12 11:59:42 +08:00
parent 49ccb5149f
commit 4f870de963
7 changed files with 68 additions and 64 deletions

View File

@@ -30,12 +30,14 @@ extern "C"
#define likely(expr) __builtin_expect((expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
#include <stdint.h>
#include <sys/types.h>
#include <netinet/in.h>
/******************************************************************************
* fixed_num_array
******************************************************************************/
#include <stdint.h>
struct fixed_num_array
{
uint64_t elems[128];
@@ -105,16 +107,16 @@ struct udp_hdr
} __attribute__((__packed__));
void build_udp_header(const char *l3_hdr, int l3_hdr_len, struct udp_hdr *udp_hdr, uint16_t udp_sport, uint16_t udp_dport, int payload_len);
void build_ip_header(struct ip *ip_hdr, uint8_t next_protocol, uint16_t ipid, const char *src_addr, const char *dst_addr, uint16_t payload_len);
void build_ether_header(struct ethhdr *eth_hdr, uint16_t next_protocol, const char *src_mac, const char *dst_mac);
void build_ip_header(struct ip *ip_hdr, uint8_t next_protocol, uint16_t ipid, const in_addr_t src_ip, const in_addr_t dst_ip, uint16_t payload_len);
void build_ether_header(struct ethhdr *eth_hdr, uint16_t next_protocol, const u_char src_mac[], const u_char dst_mac[]);
/******************************************************************************
* device
******************************************************************************/
int get_ip_by_device_name(const char *dev_name, char *ip_buff);
int get_mac_by_device_name(const char *dev_name, char *mac_buff);
int str_to_mac(const char *str, char *mac_buff);
int get_ip_by_device_name(const char *dev_name, char *ip_str);
int get_mac_by_device_name(const char *dev_name, char *mac_str);
int str_to_mac(const char *mac_str, u_char mac[]);
#define CHECKSUM_CARRY(x) (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))