Commit c0a76804 authored by Alessandro Rubini's avatar Alessandro Rubini

network: prepare for network latency tests

This commit adds the Kconfig mechanism and the pfilter rules.

The latency test socket transmists frames of a specific ether type;
the receiver must receive all such frames.  To minimize the load on the
packet filter, this adds a single rule: we already accept all PTPv2
frames, so we now "OR" to this the new ethernet type.   If the feature
is configured off, the rule uses the same PTPv2 ethertye, thus
turning in practice into a NOP.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 1b9a2bf4
......@@ -106,6 +106,10 @@ config W1
boolean
default y
config LATENCY_ETHTYPE
int
default 0
# The other ones can be set by non-developers
config IP
......@@ -396,6 +400,21 @@ config LEGACY_EEPROM
boolean
default !SDB_STORAGE
config LATENCY_PROBE
depends on DEVELOPER
bool "Build the latency probe mechanism (send/recv)"
help
The latency prober sends two frames to broadcast and
then the timestamp of their departure time. The receiver
measures the network latency and reports it.
If this option is set, the receiver is always running. The
sender is built but must be activated by the latency shell cmd.
config LATENCY_ETHTYPE
depends on LATENCY_PROBE
int "Ethtype to use for latency probing"
# This is needed to size the pp_instance data strucuture. Instead of
# including the ppsi autoconf.h, with duplicate definitions, define it
# here, as we know what the value is
......
......@@ -61,6 +61,7 @@ void pfilter_init_default(void)
uint64_t cmd_word;
int i;
static int inited;
uint32_t latency_ethtype = CONFIG_LATENCY_ETHTYPE;
/* If vlan, use rule-set 1, else rule-set 0 */
s = rule_sets + (wrc_vlan_number != 0);
......@@ -114,6 +115,22 @@ void pfilter_init_default(void)
pfilter_verbose("fixing MAC adress in rule: use %s\n",
format_mac(buf, mac));
/*
* Patch in the "latency" ethtype too. This is set at build time
* so there's not need to remember the place or the value.
*/
if (latency_ethtype == 0)
latency_ethtype = 0x88f7; /* reuse PTPv2 type: turn into NOP */
for (v = vini + 1; v < vend; v += 2) {
if (((*v >> 13) & 0xffff) == 0xcafe
&& (*v & 0x7) == OR) {
pfilter_verbose("fixing latency eth_type: use 0x%x\n",
latency_ethtype);
*v &= ~(0xffff << 13);
*v |= latency_ethtype << 13;
}
}
/* If this is the VLAN rule-set, patch the vlan number too */
for (v = vini + 1; v < vend; v += 2) {
if (((*v >> 13) & 0xffff) == 0x0aaa
......
......@@ -216,6 +216,7 @@ enum pf_symbolic_regs {
FRAME_OUR_VLAN,
FRAME_TYPE_IPV4,
FRAME_TYPE_PTP2,
FRAME_TYPE_LATENCY,
FRAME_TYPE_ARP,
FRAME_ICMP,
FRAME_UDP,
......@@ -398,8 +399,9 @@ void pfilter_init_novlan(char *fname)
pfilter_cmp(6, 0x8100, 0xffff, MOV, R_TMP);
pfilter_logic2(R_DROP, R_TMP, MOV, R_ZERO);
/* Identify some Ethertypes used later. */
/* Identify some Ethertypes used later -- type latency is 0xcafe */
pfilter_cmp(6, 0x88f7, 0xffff, MOV, FRAME_TYPE_PTP2);
pfilter_cmp(6, 0xcafe, 0xffff, OR, FRAME_TYPE_PTP2);
pfilter_cmp(6, 0x0800, 0xffff, MOV, FRAME_TYPE_IPV4);
pfilter_cmp(6, 0x0806, 0xffff, MOV, FRAME_TYPE_ARP);
......@@ -411,7 +413,7 @@ void pfilter_init_novlan(char *fname)
pfilter_cmp(11, 0x0011, 0x00ff, MOV, FRAME_UDP);
pfilter_logic2(FRAME_UDP, FRAME_UDP, AND, FRAME_IP_OK);
/* For CPU: arp broadcast or icmp unicast or ptp */
/* For CPU: arp broadcast or icmp unicast or ptp (or latency) */
pfilter_logic3(FRAME_FOR_CPU, FRAME_BROADCAST, AND, FRAME_TYPE_ARP, OR, FRAME_TYPE_PTP2);
pfilter_logic3(FRAME_FOR_CPU, FRAME_IP_OK, AND, FRAME_ICMP, OR, FRAME_FOR_CPU);
......@@ -481,8 +483,9 @@ void pfilter_init_vlan(char *fname)
/* Compare with our vlan (fake number 0xaaa) */
pfilter_cmp(7, 0x0aaa, 0x0fff, MOV, FRAME_OUR_VLAN);
/* Identify some Ethertypes used later. */
/* Identify some Ethertypes used later -- type latency is 0xcafe */
pfilter_cmp(8, 0x88f7, 0xffff, MOV, FRAME_TYPE_PTP2);
pfilter_cmp(8, 0xcafe, 0xffff, OR, FRAME_TYPE_PTP2);
pfilter_cmp(8, 0x0800, 0xffff, MOV, FRAME_TYPE_IPV4);
pfilter_cmp(8, 0x0806, 0xffff, MOV, FRAME_TYPE_ARP);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment