Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/rest_api_openapi_u64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,8 @@ paths:

`ip` may be an address or a host name, and may carry a port as `address:port`. Without a port the stream goes to 11000 for video, 11001 for audio and 11002 for debug. A multicast group from 232.0.0.0 to 239.255.255.255 is accepted in place of a single host, in which case every listener that joined the group receives the stream.

To send to a single host the device looks up that host's hardware address on the wired port, or the gateway's when the host is on another subnet. When name resolution or the hardware-address lookup fails, the call fails with 404.

Video and debug share hardware and cannot both run, so starting video stops debug first.

The streams leave through the wired Ethernet port only, whichever interface carried this request. Without an Ethernet link that has an IP address the call fails, even when WiFi is connected.
Expand Down Expand Up @@ -3397,6 +3399,10 @@ paths:
value:
errors:
- 'Unrecognized stream name ''screen'''
Network Host Resolve Error:
value:
errors:
- Network Host Resolve Error
'500':
description: Internal server error
content:
Expand Down
5 changes: 5 additions & 0 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ SUITES: Sequence[Suite] = (
# a static one, and the device uses the "Static DNS" server.
Suite("e2e", "stream-wired-link", "tests/e2e/network/stream_wired_link_test.py",
"-H @HOST@ -p @PASS@ -t @TIMEOUT@", manual=True),
# Streams leave through the wired port whichever interface asked for them:
# every pairing of the interface that starts a stream with the one that
# stops it, unicast and multicast.
Suite("e2e", "stream-routing", "tests/e2e/network/stream_routing_test.py",
"-H @HOST@ -p @PASS@ -t @TIMEOUT@"),
# Drives the machine's online file search (Assembly 64, or CommoServe on a
# C64 Ultimate), mostly with negative cases. Skips when it is unreachable.
Suite("e2e", "assembly64", "tests/e2e/io/c64/assembly64_test.py",
Expand Down
5 changes: 5 additions & 0 deletions software/api/route_streams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ API_DOC(PUT, streams, start,
"of a single host, in which case every listener that joined the group receives "
"the stream.\n"
"\n"
"To send to a single host the device looks up that host's hardware address on the "
"wired port, or the gateway's when the host is on another subnet. When name "
"resolution or the hardware-address lookup fails, the call fails with 404.\n"
"\n"
"Video and debug share hardware and cannot both run, so starting video stops "
"debug first.\n"
"\n"
Expand All @@ -38,6 +42,7 @@ API_DOC(PUT, streams, start,
PARAM("ip", "string", "Where to send the stream. An address, optionally followed by a port.", "", "192.168.1.10:11000")
RESPONSE("200", "application/json", "ErrorResponse", "The stream is running.", "")
RESPONSE_ERROR("404", "Unrecognized stream name 'screen'", "")
RESPONSE_ERROR("404", "Network Host Resolve Error", "")
RESPONSE_ERROR("500", "Wired Ethernet link is down or has no IP address", "")
)
API_CALL(PUT, streams, start, NULL, ARRAY ( { { "ip", P_REQUIRED } }))
Expand Down
7 changes: 7 additions & 0 deletions software/io/network/data_streamer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ void DataStreamer :: send_udp_packet(uint32_t ip, uint16_t port)
return;
}

// The FPGA uses the wired port, regardless of lwIP's default route.
if (!NetworkInterface::getInterface(0)->bindSocket(sockfd)) {
printf("Error binding stream socket to wired interface\n");
lwip_close(sockfd);
return;
}

memset((char*)&server, 0, sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = ip;
Expand Down
7 changes: 7 additions & 0 deletions software/io/network/debug_streamer_u2p.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ void DataStreamer :: send_udp_packet(uint32_t ip, uint16_t port)
return;
}

// The FPGA uses the wired port, regardless of lwIP's default route.
if (!NetworkInterface::getInterface(0)->bindSocket(sockfd)) {
printf("Error binding stream socket to wired interface\n");
lwip_close(sockfd);
return;
}

bzero((char*)&server, sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.s_addr = ip;
Expand Down
14 changes: 14 additions & 0 deletions software/io/network/network_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ctype.h>
#include "lwip/dhcp.h"
#include "lwip/dns.h"
#include "lwip/sockets.h"
#include "lwip/apps/mdns.h"
#include "filemanager.h"

Expand Down Expand Up @@ -492,6 +493,19 @@ bool NetworkInterface :: peekArpTable(uint32_t ipToQuery, uint8_t *mac)
return ret;
}

bool NetworkInterface :: bindSocket(int socket)
{
struct ifreq request;
memset(&request, 0, sizeof(request));

LOCK_TCPIP_CORE();
char *name = netif_index_to_name(netif_get_index(&my_net_if), request.ifr_name);
UNLOCK_TCPIP_CORE();

return name && lwip_setsockopt(socket, SOL_SOCKET, SO_BINDTODEVICE,
&request, sizeof(request)) == 0;
}

void NetworkInterface :: on_edit()
{
uint8_t mac[8];
Expand Down
1 change: 1 addition & 0 deletions software/io/network/network_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class NetworkInterface : protected ConfigurableObject
void setIpAddr(uint8_t *a);
char *getIpAddrString(char *buf, int buflen);
bool peekArpTable(uint32_t ipToQuery, uint8_t *mac);
bool bindSocket(int socket);

// callbacks
static void statusCallback(struct netif *);
Expand Down
Loading