Files
TripleCross/src/include/packet/packet_manager.h

47 lines
1.1 KiB
C
Raw Normal View History

#ifndef __PACKET_MANAGER_H__
#define __PACKET_MANAGER_H__
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/if.h>
/* BOUND CHECKING*/
static __always_inline int ethernet_header_bound_check(struct ethhdr *eth, void* data_end){
if ((void *)eth + sizeof(struct ethhdr) > data_end){
return -1;
}
return 0; //OK
}
static __always_inline int ip_header_bound_check(struct iphdr* ip, void* data_end){
if ((void *)ip + sizeof(*ip) > data_end){
return -1;
}
return 0; //OK
}
static __always_inline int tcp_header_bound_check(struct tcphdr* tcp, void* data_end){
if ((void *)tcp + sizeof(*tcp) > data_end){
return -1;
}
return 0; //OK
}
/* UTILITIES */
static __always_inline int get_protocol(void* data){
struct ethhdr *eth = data;
struct iphdr *ip = data + sizeof(*eth);
switch(ip->protocol){
case IPPROTO_TCP:
return IPPROTO_TCP;
case IPPROTO_UDP:
return IPPROTO_UDP;
default:
return -1; //Unknown and not handled.
}
}
#endif