Commit Graph

89 Commits

Author SHA1 Message Date
Martin Stein
4244aba6cb nic_router: don't call DHCP client on requests
Until now, the DHCP client was called also for DHCP requests when an interface
had a domain but yet no IP config. Now, an interface distinguishes between DHCP
requests and replies first and then accordingly calls the DHCP server or the
DHCP client if they're available. This also prevents that the DHCP client has
to handle packet headers other than that of DHCP.

Fixes #3681
2020-03-11 15:44:03 +01:00
Martin Stein
a68f3b05aa nic_router: fix lifetime of DHCP clients
Let the DHCP client be a constructible member of Interface that is constructed
only as long as the interface is attached to a domain with a dynamic IP config.
This prevents DHCP client timeouts from a period with dynamic IP config to
trigger after a reconfiguration to a static IP config. Furthermore, handle
DHCP-reply packets at an interface only when the DHCP client its constructed.
Otherwise drop such packets.

Ref #3681
2020-03-11 15:43:57 +01:00
Martin Stein
d56b21d329 nic_router: do not change ethernet header as hub
When forwarding domain-local traffic like a hub, the NIC router shouldn't
modify packets at all.

Fixes #3625
2020-02-10 14:21:47 +01:00
Martin Stein
27c2a66bbd nic_router: report link state
This adds two new boolean attributes to the <report> tag of the NIC router
configuration 'link_state' and 'link_state_triggers'. The former decides
whether to report the link state of each NIC interface (downlink, uplinks) at
the NIC router. The other decides whether to trigger reporting each time the
link state of an interface changes.

Fixes #3527
2019-11-19 14:42:23 +01:00
Martin Stein
0ed5655086 nic_router: do DHCP when re-config to dynamic IP
When re-configuring a domain from using a static IP config to using a dynamic
IP config, attached interfaces didn't react with doing DHCP discover. This bug
is fixed now and the nic_router_flood test was adapted in a way that it tests
the described behavior.

Fix #3518
2019-11-19 14:42:22 +01:00
Martin Stein
bcc049ceeb nic_router: manipulate port-forwarding port
The new configuration attributes <tcp-forward to_port="123" /> and
<udp-forward to_port="123" /> enable manipulating the destination port of
port-forwarded packets.

Fixes #3237
2019-04-01 19:33:48 +02:00
a2bdcc68c2 Throw exception for invalid packets at packet streams
Some application code is dereferencing the pointer returned by
'packet_content' at packet streams without checking that it is valid.
Throw an exception rather than return a null pointer, except for
zero-length packets, which have somewhat implicit invalid content and
that we believe to be properly handled in all current cases.

The client-side of a packet stream cannot take corrective action if the
server-side is sending packets with invalid content, but the servers
that provide packet streams should catch this exception to detect
misbehaving clients.

Ref #3059
2018-11-29 11:54:29 +01:00
Martin Stein
304cb290d9 nic_router: rework quota accounting
* Account all RAM/CAP quota of a session except quota for metadata used in
  core. The latter is considered when asking if a session can afford to make
  an operation but it does not get accounted to always be able to pay back all
  quota when a session closes. The general accounting mechanism is moved from
  atop of the allocators down to the level of RAM/RM session operations.
* report statistics about session objects and quota if <report stats="yes"
  quota="yes"/> is configured. (default is yes if <report> is present)

Issue #2953
2018-10-29 09:36:21 +01:00
Martin Stein
3db7181104 nic_router: limit packets handled per signal
Make it configurable how many packets get handled at a max per signal to
prevent DoS attacks by clients.

Issue #2953
2018-10-29 09:36:21 +01:00
Martin Stein
d6c6549354 nic_router: destroy links on insufficient resource
If the NIC router has insufficient CAP or RAM quota for the creation of
a state object for an interface, it tries to destroy a certain amount of
existing state objects of this interface to free resources. Afterwards,
it retries handling the current packet once. If it does fail again, the
router drops the packet.

Issue #2953
2018-10-29 09:36:21 +01:00
Martin Stein
4442c79526 nic_router: "packet alloc" error only when verbose
Issue #2953
2018-10-29 09:36:21 +01:00
Martin Stein
495490743c nic_router: log ARP decisions when verbose
In verbose mode, some types of ARP packets were handled without any log about
what was done.

Issue #2899
2018-08-02 14:36:35 +02:00
Martin Stein
2733d3fea5 nic_router: verbose_packet_drop attribute
The log messages covered by verbose_packet_drop were previously
configured by the verbose attribute. This isn't the case anymore. Now,
you can configure them as follows:

! <config verbose_packet_drop="no" ... >
!     <domain verbose_packet_drop="no" ... />
! <config/>

The new attribute determines whether to log each packet drop and the
rational behind it. The <config> value affects all domains without a
<domain> local value.

Issue #2857
2018-06-29 10:44:59 +02:00
Martin Stein
0b8520a208 nic_router: act as ICMP Echo server
The ICMP-Echo-server functionality of the router has the following
configuration attributes (default values shown):

! <config icmp_echo_server="yes">
!    <domain icmp_echo_server="yes" ... />
! </config>

The icmp_echo_server attribute configures whether the router answers ICMP Echo
requests that address the router. The <config> value affects all domains
without a <domain> local value.

Issue #2874
2018-06-29 10:44:58 +02:00
Martin Stein
9b619e95b2 nic_router: fix log when updating ARP waiters
Give the correct reason why an ARP waiter was dismissed.

Issue #2840
2018-06-29 10:44:58 +02:00
Martin Stein
90fcba79c6 nic_router: non-critical logs only when verbose
* Do not log events that are not critical (deadly) to the NIC router if not
  configured to be verbose,
* Print almost all log lines with a prefix of the domain name they are
  related to,
* And, do not use Genode::error and Genode::warning as they make it hard to
  read the log with the domain name prefixes.

Fixes #2840
2018-06-29 10:44:53 +02:00
Martin Stein
49a3a0e0d0 nic_router: multiple uplinks
Introduce the uplink tag:

! <config>
!    <uplink label="wifi"  domain="uplink">
!    <uplink label="wired" domain="wired_bridge">
!    <uplink               domain="wired_bridge">
! <config/>

For each uplink tag, the NIC router requests a NIC session with the
corresponding label or an empty label if there is no label attribute.
These NIC sessions get attached to the domain that is set in their
uplink tag as soon as the domain appears. This means their lifetime is
not bound to the domain. Uplink NIC sessions can be safely moved from
one domain to another without being closed by reconfiguring the
corresponding domain attribute.

Attention: This may render previously valid NIC router configurations
useless. A domain named "uplink" doesn't automatically request a NIC
session anymore. To fix these configurations, just add

! <uplink domain="uplink"/>

or

! <uplink label="[LABEL]" domain="uplink"/>

as direct subtag of the <config> tag.

Issue #2840
2018-06-29 10:44:53 +02:00
Martin Stein
bf055e2cb4 nic_router: fix uncaught interface RAM exhaustion
* Catch Quota_guard exceptions wherever we do 'new (_alloc)' in Interface
  and in case drop the packet that caused the exception
* Modify Interface::handle_config_2 to not use the guarded allocator of the
  NIC session quota as we cannot handle a RAM exhaustion well at this point
  in time. Instead use a Constructible member in Interface so that a needed
  RAM adds up to the calculation in the create_session implementation where
  an exhaustion is handled via a service denial.

Issue #2857
2018-06-12 12:11:50 +02:00
Martin Stein
97ea513122 nic_router: fix pure virtual call in ~Interface()
The interface destructor called pure virtual methods at least when
cancelling ARP- waiting states. The implementations were made by the
deriving classes Session_component respectively Uplink. This led to an
abort of the NIC router as the destruction of the derived class was
already done. A similar problem already occured in the past during the
construction of Interface and was back then solved by introducing a
separate init() method. This commit, however, solved the problem by
making Interface a member of the other classes. Therefore, the init()
method could be removed again. Furthermore, the interface polica could be
moved from Session_component_base to Session_component. The commit also
had to generalize the way the link state of an interface is determined.

Fixes #2856
2018-06-12 12:11:49 +02:00
Martin Stein
a3905fcf87 nic_router: do not leak packets on link down/up
Do not send nor buffer packets at interfaces with link state "down". This
prevents that packets that were routed to one network (allowed to see them),
due to a sudden link down/up, are leaked to another network that is not
allowed to see them.
2018-05-31 12:28:15 +02:00
Martin Stein
1306892fbf nic_router: fix interface update on missing domain
When updating an interface in the NIC router to a new configuration and
the domain name of the interface has not changed but the domain
disappeared, the NIC router did not detach from the old domain correctly
which led to broken remnants of interface state objects (like connection
states).

Adapt the nic_router_uplinks run script to work with the fix.
2018-05-31 12:28:15 +02:00
Martin Stein
c32c584f65 nic_router: fix uncaught exception on re-configure 2018-05-30 13:36:38 +02:00
Martin Stein
4802d22527 nic_router: reset uplink IP on link state change 2018-05-30 13:36:38 +02:00
Martin Stein
fe21ab48e0 nic_router: fix link-state for uplink interface 2018-05-30 13:36:37 +02:00
Martin Stein
ba348b73e2 nic_router: re-use dynamic IPv4 config if possible
When re-configuring the NIC router, determine for each domain if at least one
interface stays with the domain. If a domain fullfills this and has a
dynamic IP config (received via a DHCP client), keep the IP config.

To achieve this, the following changes have been made to the existing NIC
router code:

* Split-up Interface::handle_config into three steps:

  1) Determine for each interface if its domain can keep its IP config or
     or if it has to mark it invalid. This must be done before (re-)attaching
     any interface because during "attach" several decisions are made based on
     the validity of the IP config of corresponding the domain.
     (E.g. whether to participate in sending DHCP DISCOVERs {IP config
     invalid} or whether to participate in sending pending ARP REQUESTs
     {IP config valid} ).

  2) Detach, attach, or re-attach each interface according to the
     configuration. This must be done before re-considering the temporary
     state objects of each interface because the latter might have effects
     on the interfaces of remote domains which must then be in place already.

  3) Re-consider temporary state objects of each interface. (E.g. transport
     layer connection states)

* Re-work IP-config setter in a way that it works as follows:

  1) If the old IP config is valid, let all local interfaces as well as remote
     interfaces that depend on the IP config of the domain detach from the old
     IP config.

  2) Overwrite with new IP config

  3) If the new IP config is valid, let all local interfaces as well as remote
     interfaces that depend on the IP config of the domain attach to the new
     IP config.

Issue #2815
2018-05-30 13:36:34 +02:00
Martin Stein
0d5ed994e2 nic_router: fix dst and client MAC in DHCP replies
The Ethernet destination MAC address of a DHCP reply is not the same as the
DHCP client MAC address. The DHCP server of the NIC router did not take care
of this by now.

Issue #2837
2018-05-30 13:36:33 +02:00
Martin Stein
3d480ec947 nic_router: fix config update of ICMP links
Previously, the update of ICMP links on a new router configuration lead to an
uncaught exception.

Issue #2795
2018-05-30 13:36:19 +02:00
Martin Stein
e83f095fd2 nic_router: downlinks use own router MAC address
Allocate a virtual MAC address at runtime that is used as router
Ethernet-identity for all downlink domains. This makes the downlink
domains independent from the uplink session.

Issue #2795
2018-05-30 13:36:11 +02:00
Martin Stein
980f3e9c5c net: use Size_guard for packet-data accessors
Instead of handing over the maximum available size to the packet data
accessors, hand over a size guard that keeps track of the packets
boundaries.

This commit also moves the size-guard utilitiy header of Ping and NIC
Router to the include/net directory making it a part of the net library.
It applies the new approach to all net-lib users in the basic repositories.

Ping looses its configurability regarding the ICMP data size as this would
require an additional method in the size guard which would be used only by
Ping.

The size guard was also re-worked to fit the fact that a packet can
bring a tail as well as a header (Ethernet).

Issue #2788
2018-05-30 13:36:11 +02:00
Martin Stein
11a297b557 net: consider tail of Ethernet frame
The Ethernet payload may be followed by padding of variable length and
the FCS (Frame Check Sequence). Thus, we should consider the value
"Ethernet-frame size minus Ethernet-header size" to be only the maximum
size of the encapsulated IP packet. But until now, we considered it to
be also the actual size of the encapsulated IP packet. This commit fixes
the problem for all affected components of the Genode base-repository.

Fixes #2775
2018-05-03 15:31:57 +02:00
Martin Stein
6b55790e73 net: use generic internet checksum
This reduces the redundant implementations of checksum calculation to
one generic implementation, makes the checksum interface conform over
all protocols, and brings performance optimizations. For instance,
the checksum is now calculated directly in big endian which saves us
most of the previously done byte-re-ordering.

Issue #2775
2018-05-03 15:31:56 +02:00
Martin Stein
373134c4e7 net: safer access to packet data
Replace packet method 'T *data' by the new methods 'T &reinterpret_data'
for parsing or modifying existing sub-protocol packets and 'T
&construct_at_data' for composing a new sub-protocol packet. This has
the advantage that, when composing a new packet, the default constructor
that zero-fills the packet is always called first.

Fixes #2751
2018-05-03 15:31:54 +02:00
Martin Stein
87eb23f562 nic_router: fix uncaught Domain_tree::No_match
When having an interface that yet is not attached to a domain, then a new
configuration comes in and the interface receives a domain name (via the
policy tag) but the corresponding domain doesn't exist, an exception
Domain_tree::No_match is thrown but was not caught and handled until now.

Issue #2670
2018-04-10 11:11:54 +02:00
Martin Stein
54b10b1b38 nic_router: forward ICMP dst unreachable messages
This follows the guidelines in RFC 5508 to enable forwarding of ICMP
"Destination Unreachable" that correspond to an existing link state in
the NIC router. It also serves as blueprint for forwarding ICMP error
messages in general (They are merely not enabled because we don't test
them).

Issue #2732
2018-04-10 11:11:54 +02:00
Martin Stein
6a988749a1 nic_router: print packet info before sending it
By now, the 'verbose packets' output when sending packets was printed after
finish sending the packet. This makes following the packet flow harder if you
have multiple components that print such information.

Issue #2732
2018-04-10 11:11:54 +02:00
Martin Stein
7b3343c2dc nic_router: NAPT for ICMP echo messages
This follows the guidelines in RFC 5508 to enable ICMP echo through a NAPT
channel of the NIC router. It serves also as blueprint for ICMP queries in
general (they are merely not enabled because we don't test them by now).

Issue #2732
2018-04-10 11:11:53 +02:00
Martin Stein
8981d3baf5 nic_router: conform log in Interface::_handle_eth
Prefix "Drop Packet" messages always with "[<DOMAIN>]".

Issue #2732
2018-04-10 11:11:53 +02:00
Martin Stein
9b936dd120 nic_router: packet verbose at detached interfaces
The 'verbose packets' output previously was not generated for Interfaces
without a domain. But this is desirable as the router nonetheless
receives packets at such interfaces. This is now fixed and such output
is simply prefixed with a "[?]" denoting that the interface has no
domain.

Issue #2732
2018-04-10 11:11:53 +02:00
Martin Stein
98617432c3 nic_router: send ICMP error on unroutable packet
Send an ICMP "Destination Network Unreachable" as response to packets that
are not routable by the NIC router.

Issue #2732
2018-04-10 11:11:52 +02:00
Martin Stein
4dc8f6dca4 nic_router: fix missing IPv4.ECN initialization
We missed to zero-out the ECN field in IPv4 packets. We don't use the ECN
field but there might be old data left in the packet RAM allocated by the
NIC packet streams. If we don't zero-out ECN it might leak old data.

Issue #2732
2018-04-10 11:11:52 +02:00
Martin Stein
e213b9046d nic_router: inform clients on DNS server change
If the remote DNS server address value of a DHCP server changes, the affected
interfaces do a link down/up to inform all DHCP clients that they should
re-request their DHCP info.

Issue #2730
2018-04-10 11:06:00 +02:00
Martin Stein
b344f2bc39 nic_router: fix pure virtual call in Interface
The Interface constructor previously tried to attach to a domain.  This
might include sending a DHCP request to get the domain a valid IP config.
But in order to achieve this, the constructor used a pure virtual method
of Interface which crashes due to the unfinished vtable. To fix this bug,
the attach attempt was moved to a new Interface::init method.

Issue #2730
2018-03-29 16:09:52 +02:00
Martin Stein
1044c2fcab nic_router: simplify the pointer utility
Instead of Pointer<T>::set use assignment operator with implicit constructor
from T-reference. Instead of Pointer<T>::unset use assignment operator with
Pointer<T>(). Instead of Pointer<T>::deref provide () operator.

Issue #2730
2018-03-29 16:03:28 +02:00
Martin Stein
92a30e0953 nic_router: handle configuration changes
The router reacts as follows to a configuration change:

1) Construct new internal configuration representation (the old one stays
   in place to be able to do comparisons in the following steps)
2) Iterate through all user-dependent objects (interfaces, link states, ARP
   information, DHCP information) and re-check which remain valid with the
   new configuration and which must be dismissed.
3) Adapt the objects that remain valid to the new configuration (re-write
   references) and remove or detach the dismissed objects.
4) Do a link state DOWN at each interface and a link state UP at each
   interface that remains attached to a domain.
5) Replace the old internal configuration representation with the new one

This way, the router keeps as much user dependent states as possible
while going through a configuration change. Thus, overwriting the old
configuration with an exact copy of itself is (almost) transparent to
clients of the router. Almost, because there are things the router must
do on every configuration handling, like re-scheduling the expiration
timeouts of links.

Ref #2670
2018-03-29 15:39:44 +02:00
Martin Stein
2c2037952d nic_router: support interfaces without a domain
Clients can connect at any time to the NIC router. The interfaces (sessions)
get attached to the appropriate domain as soon as it appears. This implies
that interfaces can also be detached from a domain without beeing destructed
when the domain disappears. All user dependent states of an interface such as
the link states, DHCP allocations and ARP information get lost when the
interface gets detached.

Ref #2670
2018-03-29 15:22:34 +02:00
Martin Stein
63de13b50e nic_router: conform domain labeling in log
Adapt domain labeling of packet receive/send messages in log to other domain
specific log messages.

Ref #2670
2018-03-29 15:21:07 +02:00
Martin Stein
2a77976164 nic_router: add verbose_packets per domain
A domain logs its packets if one of the global 'verbose_packets' or its local
'verbose_packets' is switched on.

Ref #2670
2018-03-29 15:20:20 +02:00
Martin Stein
bd16f89617 nic_router: add verbose_packets attribute
This separates the decision wether to log the received and sent packets
from the 'verbose' attribute. This information is now only logged if
'verbose_packets' is switched on. If 'verbose' is switched on, only
routing decisions and optional hints are printed.

Ref #2670
2018-03-29 15:20:15 +02:00
Martin Stein
6575df84c5 nic_router: fix use of outdated ARP-cache entries
When a NIC session is destructed at the router, we have to remove all ARP
cache entries that match the MAC address of that session. Otherwise the
outdated entries might be re-applied later, leading to wrong destination
MAC addresses in routed packets.

Fixes #2637
2018-02-09 13:34:16 +01:00
Martin Stein
f4a2d932e3 net: check packet data size in accessor
Instead of having a method validate_size in each packet class, check
sizes in the data accessor of the surrounding packet class. This packet
accessor is the one that casts the data pointer to the desired data type
so it is sensible that it also checks whether the desired type would
exceed the available RAM before doing the cast. This also fits nicely
the fact that for the top-level packet-class of a packet, the size must
not be checked (which was previously done).

Issue #465
2018-01-17 12:14:41 +01:00