bugfix:mirror流量的MAC地址是默认值

This commit is contained in:
wangmenglan
2024-11-06 14:26:18 +08:00
parent be0bdc08e3
commit d4d76f0951
3 changed files with 88 additions and 43 deletions

View File

@@ -1323,6 +1323,37 @@ int packet_get_outermost_tuple6(const struct packet *handler, struct tuple6 *tup
}
}
int packet_get_outermost_mac(const struct packet *handler, unsigned char *src_mac, unsigned char *dst_mac)
{
const struct layer_record *layer_l2 = NULL;
const struct layer_record *layer = NULL;
struct ethhdr *ethhdr = NULL;
for (int8_t i = 0; i < handler->layers_used; i++)
{
layer = &handler->layers[i];
// first get L2 layer
if (layer->type & LAYER_TYPE_ETHER)
{
layer_l2 = layer;
break;
}
}
if (layer_l2)
{
ethhdr = (struct ethhdr *)handler->data_ptr;
memcpy(src_mac, ethhdr->h_source, ETH_ALEN);
memcpy(dst_mac, ethhdr->h_dest, ETH_ALEN);
return 0;
}
else
{
return -1;
}
}
const struct layer_record *packet_get_innermost_layer(const struct packet *handler, enum layer_type type)
{
const struct layer_record *layer = NULL;