-
Notifications
You must be signed in to change notification settings - Fork 29
vswitch: add vswitch component #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JDuchniewicz
wants to merge
35
commits into
main
Choose a base branch
from
jakub/vswitch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
ee2daf8
network: port vswitch from alexandermbrown
JDuchniewicz bdfb708
vswitch: adapt to new microkit
JDuchniewicz ee1664c
vswitch: Design the config structure
JDuchniewicz 1dd43b1
vswitch: flesh out sending
JDuchniewicz f485b5f
vswitch: first implementation
JDuchniewicz d8bac98
vswitch: fixup rx and tx, minor vswitch fixes
JDuchniewicz 36dd5b0
vswitch: fixups for compilation
JDuchniewicz b00e56b
vswitch: Makefile fixes
JDuchniewicz 0561e6d
vswitch: debugging and small fixes
JDuchniewicz b6a0f41
vswitch: add copiers having mappings to other pds
JDuchniewicz 4692785
vswitch: Fix wrong default port. virt buf.oid stamping
JDuchniewicz f29adf0
ubsan: fix wrong cast
JDuchniewicz becb77c
vswitch: add logs to eth driver
JDuchniewicz c3cd650
vswitch: cleanup logs
JDuchniewicz 907d496
vswitch: cleanup
JDuchniewicz 4caaa06
style: lint
JDuchniewicz 1a06d68
address review comments
JDuchniewicz e2e88d7
vswitch: fix up naming
JDuchniewicz fe15135
vswitch: drop packets when client's queues are full
JDuchniewicz ef8c0c0
vswitch: remove multiple MACs scaffoling
JDuchniewicz 42e0775
vswitch: remove hardcoded buffer size
JDuchniewicz 0bbef98
vswitch: address some review comments
JDuchniewicz 00123af
vswitch: more review remarks
JDuchniewicz 43c70ef
vswitch: change to num_ports instead of hardcode
JDuchniewicz 05294bd
vswitch: batch signalling
JDuchniewicz a87c1e6
vswitch: add assertions and debug checks
JDuchniewicz cb82141
vswitch: add ACL support
JDuchniewicz 9e46e68
vswitch: address review comments
JDuchniewicz 1743581
vswitch: fix wrong buffer sizes assumption
JDuchniewicz 9cc9576
vswitch: Prevent flooding the clients with packets
JDuchniewicz bc635eb
vswitch: Drop packet if no virt connected and cannot match any port
JDuchniewicz dc0174d
vswitch: style fixes
JDuchniewicz 62d7e5a
vswitch: add checksum zeroing for DHCP packets
JDuchniewicz ad0eb25
vswitch: build fix
JDuchniewicz 794985b
vswitch: add more robust checksum clearing for all protocols
JDuchniewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright 2025, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| /* ----------------- ICMP Protocol Definitions ---------------------------*/ | ||
|
|
||
| /* Shared ICMP header prefix accross all control types */ | ||
| typedef struct __attribute__((__packed__)) icmp_hdr { | ||
| /* ICMP type */ | ||
| uint8_t type; | ||
| /* ICMP sub-type */ | ||
| uint8_t code; | ||
| /* internet checksum calculated over ICMP header and data */ | ||
| uint16_t check; | ||
| /* The following 4 bytes of the header are ICMP type dependent */ | ||
| } icmp_hdr_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright 2026, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| typedef struct __attribute__((__packed__)) ipv4_hdr { | ||
| /* internet header length in 32-bit words, variable due to optional fields */ | ||
| uint8_t ihl : 4; | ||
| /* IP version, always 4 for IPv4 */ | ||
| uint8_t version : 4; | ||
| /* explicit congestion notification, optional */ | ||
| uint8_t ecn : 2; | ||
| /* differentiated services code point */ | ||
| uint8_t dscp : 6; | ||
| /* total packet length in bytes, including header and data */ | ||
| uint16_t tot_len; | ||
| /* identifier of packet, used in packet fragmentation */ | ||
| uint16_t id; | ||
| /* offset in 8 bytes of fragment relative to the beginning of the original | ||
| unfragmented IP datagram. Fragment offset is a 13 byte value split accross | ||
| frag_offset1 and frag_offset2 */ | ||
| uint8_t frag_offset1 : 5; | ||
| /* if packet belongs to fragmented group, 1 indicates this is not the last | ||
| fragment */ | ||
| uint8_t more_frag : 1; | ||
| /* specifies whether datagram can be fragmented or not */ | ||
| uint8_t no_frag : 1; | ||
| /* reserved, set to 0 */ | ||
| uint8_t reserved : 1; | ||
| /* offset in 8 bytes of fragment relative to the beginning of the original | ||
| unfragmented IP datagram. Fragment offset is a 13 byte value split accross | ||
| frag_offset1 and frag_offset2 */ | ||
| uint8_t frag_offset2; | ||
| /* time to live, in seconds but in practice router hops */ | ||
| uint8_t ttl; | ||
| /* transport layer protocol of encapsulated packet */ | ||
| uint8_t protocol; | ||
| /* internet checksum of IPv4 header */ | ||
| uint16_t check; | ||
| /* source IP address */ | ||
| uint32_t src_ip; | ||
| /* destination IP address */ | ||
| uint32_t dst_ip; | ||
| /* optional fields excluded */ | ||
| } ipv4_hdr_t; | ||
|
|
||
| /* Offset of the start of the IPV4 header */ | ||
| #define IPV4_HDR_OFFSET ETH_HDR_LEN | ||
|
|
||
| /* Length of IPv4 header with no optional fields */ | ||
| #define IPV4_HDR_LEN_MIN sizeof(ipv4_hdr_t) | ||
|
|
||
| /* IPv4 differentiated services code point values */ | ||
| #define IPV4_DSCP_NET_CTRL 48 /* Network control */ | ||
|
|
||
| /* IPv4 transport layer protocols */ | ||
| #define IPV4_PROTO_ICMP 0x01 | ||
| #define IPV4_PROTO_TCP 0x06 | ||
| #define IPV4_PROTO_UDP 0x11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright 2026, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
| #include <sddf/util/printf.h> | ||
|
|
||
| #define PR_MAC802_ADDR "%x:%x:%x:%x:%x:%x" | ||
|
|
||
| /* Expects a *pointer* to a struct ether_hdr */ | ||
| #define PR_MAC802_ADDR_ARGS(a, dir) (a)->##dir##->addr[0], \ | ||
| (a)->##dir##->addr[1], \ | ||
| (a)->##dir##->addr[2], \ | ||
| (a)->##dir##->addr[3], \ | ||
| (a)->##dir##->addr[4], \ | ||
| (a)->##dir##->addr[5] | ||
|
|
||
| #define PR_MAC802_DEST_ADDR_ARGS(a) PR_MAC802_ADDR_ARGS(a, dest) | ||
| #define PR_MAC802_SRC_ADDR_ARGS(a) PR_MAC802_ADDR_ARGS(a, src) | ||
|
|
||
| #define MAC802_BYTES 6 | ||
| #define ETH_TYPE_IP 0x0800U | ||
|
|
||
| typedef struct mac_addr { | ||
| uint8_t addr[MAC802_BYTES]; | ||
| } mac_addr_t; | ||
|
|
||
| /* Ethernet packet header */ | ||
| typedef struct ether_hdr { | ||
| mac_addr_t dest; | ||
| mac_addr_t src; | ||
| uint8_t etype[2]; // Ethertype | ||
| } __attribute__((__packed__)) ether_hdr_t; | ||
|
|
||
| static inline bool mac802_addr_eq_num(const uint8_t *addr0, const uint8_t *addr1, unsigned int num) | ||
| { | ||
| for (int i = 0; i < num; i++) { | ||
| if (addr0[i] != addr1[i]) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| static inline bool mac802_addr_eq(const uint8_t *addr0, const uint8_t *addr1) | ||
| { | ||
| return mac802_addr_eq_num(addr0, addr1, MAC802_BYTES); | ||
| } | ||
|
|
||
| static inline bool mac802_addr_is_bcast(const uint8_t *addr) | ||
| { | ||
| const uint8_t bcast_macaddr[MAC802_BYTES] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; | ||
| return mac802_addr_eq(addr, bcast_macaddr); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2025, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| /* ----------------- TCP Protocol Definitions ---------------------------*/ | ||
|
|
||
| typedef struct __attribute__((__packed__)) tcp_hdr { | ||
| /* source port */ | ||
| uint16_t src_port; | ||
| /* destination port */ | ||
| uint16_t dst_port; | ||
| /* sequence number */ | ||
| uint32_t seq; | ||
| /* acknowledgement number */ | ||
| uint32_t ack_seq; | ||
| /* reserved, set to 0 */ | ||
| uint16_t reserved : 4; | ||
| /* size of the TCP header in 32 bit words */ | ||
| uint16_t doff : 4; | ||
| /* fin */ | ||
| uint16_t fin : 1; | ||
| /* syn */ | ||
| uint16_t syn : 1; | ||
| /* reset */ | ||
| uint16_t rst : 1; | ||
| /* push */ | ||
| uint16_t psh : 1; | ||
| /* ack */ | ||
| uint16_t ack : 1; | ||
| /* urgent pointer is valid */ | ||
| uint16_t urg : 1; | ||
| /* ECN-Echo*/ | ||
| uint16_t ece : 1; | ||
| /* congestion window reduced */ | ||
| uint16_t cwr : 1; | ||
| /* size of the receive window*/ | ||
| uint16_t window; | ||
| /* checksum over the TCP packet and psuedo-header */ | ||
| uint16_t check; | ||
| /* urgent pointer */ | ||
| uint16_t urg_ptr; | ||
| /* optional fields excluded */ | ||
| } tcp_hdr_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright 2025, UNSW | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| /* ----------------- UDP Protocol Definitions ---------------------------*/ | ||
|
|
||
| typedef struct __attribute__((__packed__)) udp_hdr { | ||
| /* source port */ | ||
| uint16_t src_port; | ||
| /* destination port */ | ||
| uint16_t dst_port; | ||
| /* length in bytes of the UDP datagram including header */ | ||
| uint16_t len; | ||
| /* checksum over the UDP datagram and psuedo-header, optional for IPv4 */ | ||
| uint16_t check; | ||
| } udp_hdr_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.