|
@@ -66,40 +66,18 @@ unsafe fn matches_filter(daddr: IpAddr) -> bool {
|
|
|
fn try_responder(ctx: XdpContext) -> Result<xdp_action::Type, xdp_action::Type> {
|
|
|
let mut hdr_cursor = 0usize;
|
|
|
|
|
|
- // let eth = parse_ethhdr(&ctx, &mut hdr_cursor).ok_or(xdp_action::XDP_PASS)?;
|
|
|
- // let protocol = unsafe { u16::from_be((*eth).h_proto) };
|
|
|
-
|
|
|
- // if protocol != ETH_P_IP {
|
|
|
- // return Ok(xdp_action::XDP_PASS);
|
|
|
- // }
|
|
|
-
|
|
|
- // let ip = parse_ipv4hdr(&ctx, &mut hdr_cursor).ok_or(xdp_action::XDP_PASS)?;
|
|
|
- //
|
|
|
-
|
|
|
let (eth, ip) = unsafe {
|
|
|
parse_routing(&ctx, &mut hdr_cursor)
|
|
|
.ok_or(xdp_action::XDP_PASS)?
|
|
|
};
|
|
|
|
|
|
- let (protocol, daddr) = match ip {
|
|
|
- Layer3::Ipv4(ip) => unsafe { (
|
|
|
- (*ip).protocol,
|
|
|
- IpAddr::V4((*ip).daddr)
|
|
|
- ) },
|
|
|
- Layer3::Ipv6(ip) => unsafe {(
|
|
|
- (*ip).nexthdr,
|
|
|
- IpAddr::V6((*ip).daddr)
|
|
|
- ) }
|
|
|
- };
|
|
|
-
|
|
|
+ let protocol = unsafe { l3_get_protocol(&ip) };
|
|
|
+ let daddr = unsafe { l3_get_daddr(&ip) };
|
|
|
|
|
|
if is_local(daddr) {
|
|
|
- // info!(&ctx, "local: pass");
|
|
|
- return Ok(xdp_action::XDP_PASS);
|
|
|
+ return Ok(xdp_action::XDP_PASS); // Pass normal loopback traffic to not disturb host
|
|
|
}
|
|
|
|
|
|
- info!(&ctx, "received a packet");
|
|
|
- info!(&ctx,"Received eth with proto: {}", protocol);
|
|
|
info!(&ctx, "Received ip with proto: {}", protocol);
|
|
|
match daddr {
|
|
|
IpAddr::V4(ip) => info!(&ctx, "daddr: {:ipv4}", ip),
|