L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
filter.cc
1/*
2 * Copyright (C) 2016-2017, 2024 Kernkonzept GmbH.
3 * Author(s): Jean Wolter <jean.wolter@kernkonzept.com>
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7#include "filter.h"
8
9/* This is an example filter and therefore rather verbose. A real
10 filter would not produce any output */
11
12bool
13filter(const uint8_t *buf, size_t size)
14{
15 // Packet large enough to apply filter condition?
16 if (size <= 13)
17 return false;
18
19 uint16_t ether_type = (uint16_t)*(buf + 12) << 8
20 | (uint16_t)*(buf + 13);
21 char const *protocol;
22 switch (ether_type)
23 {
24 case 0x0800: protocol = "IPv4"; break;
25 case 0x0806: protocol = "ARP"; break;
26 case 0x8100: protocol = "Vlan"; break;
27 case 0x86dd: protocol = "IPv6"; break;
28 case 0x8863: protocol = "PPPoE Discovery"; break;
29 case 0x8864: protocol = "PPPoE Session"; break;
30 default: protocol = nullptr;
31 }
32 if (protocol)
33 printf("%s\n", protocol);
34 else
35 printf("%04x\n", ether_type);
36
37 if (ether_type == 0x0806)
38 {
39 printf("Do not filter arp\n");
40 return false;
41 }
42
43 return true;
44}