Skip to content
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

Add IPv6 support #25

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6b8ce9e
create_send_sock() - improve error handling
Alphix Feb 4, 2024
2ca8a23
create_send_sock() - reorganise function a bit
Alphix Feb 4, 2024
5cf1522
create_send_sock() - dynamically allocate sockdata
Alphix Feb 4, 2024
05c6c07
Use stdbool.h to define booleans
Alphix Feb 4, 2024
afedb26
Use a linked list to keep track of send socks
Alphix Feb 4, 2024
0552d4d
Add list.h
Alphix Feb 4, 2024
ccfd792
Rename parse() as parse_subnet() and simplify error handling
Alphix Feb 4, 2024
5b7e840
Simplify parse_subnet()
Alphix Feb 4, 2024
c24631a
Convert the subnet black/whitelists to linked lists
Alphix Feb 4, 2024
7c72575
Add subnet_match() helper function
Alphix Feb 4, 2024
6bdef46
Create some socket/subnet print helpers
Alphix Feb 4, 2024
5a737a1
Add a signal pipe
Alphix Feb 4, 2024
c1cc11a
Switch from select() to poll()
Alphix Feb 4, 2024
f4d788f
Turn receiving sockets into a list as well
Alphix Feb 4, 2024
e551477
Rename struct if_sock to send_sock
Alphix Feb 4, 2024
9754065
Support IPv6 in recvfrom
Alphix Feb 4, 2024
c830507
Support IPv6 in subnets (blacklist/whitelist)
Alphix Feb 4, 2024
b842c61
Support IPv6 in recv_sock()
Alphix Feb 5, 2024
5cd3579
Use IP_MULTICAST_IF instead of SO_BINDTODEVICE
Alphix Feb 6, 2024
6652c4d
Use IPv4/IPv6 agnostic storage for send_sock addresses
Alphix Feb 6, 2024
e49c9c6
Add a separate create_send_sock6() function
Alphix Feb 6, 2024
2e27cce
Add IPV6_V6ONLY to create_recv_sock6()
Alphix Feb 6, 2024
9d65bcc
Split send_socks into separate v4/v6 lists
Alphix Feb 6, 2024
9336530
Move packet repetition logic to separate functions
Alphix Feb 6, 2024
d88f61c
Move packet reception to a separate function
Alphix Feb 6, 2024
14282d8
Reorganize structs a bit
Alphix Feb 6, 2024
32b08bc
Create a struct for addr/mask/net tuples
Alphix Feb 6, 2024
8bcbb1c
Remove struct subnet, use struct addr_mask instead
Alphix Feb 6, 2024
d410c0f
Create separate send_sock structs for IPv4 and IPv6
Alphix Feb 6, 2024
2d41311
Change struct send_sock6 to include a list of nets
Alphix Feb 6, 2024
1e1d59c
Add proper address determination to create_send_sock6()
Alphix Feb 6, 2024
1a39f02
Split recv_packet() into v4/v6 versions
Alphix Feb 6, 2024
cad3763
Improve recv_packet6() to get ifindex
Alphix Feb 6, 2024
f37d382
Split subnet_match into v4/v6 versions
Alphix Feb 7, 2024
cf08782
Split send_packet() into v4/v6 functions
Alphix Feb 7, 2024
1ec0df1
Fix a bug in the IPv6 subnet matching function
Alphix Feb 7, 2024
bf48652
Use the new same_network() function in other places as well
Alphix Feb 7, 2024
d887376
Add a same_address() helper function
Alphix Feb 7, 2024
4681357
Make more use of the log_message() function
Alphix Feb 7, 2024
7cc7e2c
Add a malloc() wrapper
Alphix Feb 7, 2024
d39410b
Add -4 and -6 command line options and update help text
Alphix Feb 7, 2024
756b854
Update README
Alphix Feb 7, 2024
75966e2
Add a .gitignore file
Alphix Feb 7, 2024
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
Prev Previous commit
Next Next commit
Make more use of the log_message() function
  • Loading branch information
Alphix committed Feb 7, 2024
commit 46813579a3115ec82aa58983e7494d6615e3e817
49 changes: 26 additions & 23 deletions mdns-repeater.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ void log_message(int loglevel, char *fmt_str, ...) {
va_list ap;
char buf[2048];

if (loglevel == LOG_DEBUG && !foreground)
return;

va_start(ap, fmt_str);
vsnprintf(buf, 2047, fmt_str, ap);
va_end(ap);
Expand Down Expand Up @@ -915,39 +918,39 @@ repeat_packet6(struct recv_sock *recv_sock, unsigned ifindex)
list_for_each_entry(send_sock, &send_socks6, list) {
list_for_each_entry(am, &send_sock->ams, list) {
if (same_address(&recv_sock->from, &am->addr)) {
if (foreground)
printf("skipping packet from=%s size=%zd (ourself)\n",
recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"skipping packet from=%s size=%zd (ourself)",
recv_sock->from_str, recv_sock->pkt_size);
return;
}
}
}

if (!list_empty(&whitelisted_subnets) &&
!subnet_match(&recv_sock->from, &whitelisted_subnets)) {
if (foreground)
printf("skipping packet from=%s size=%zd (not whitelisted)\n",
recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"skipping packet from=%s size=%zd (not whitelisted)",
recv_sock->from_str, recv_sock->pkt_size);
return;
}

if (subnet_match(&recv_sock->from, &blacklisted_subnets)) {
if (foreground)
printf("skipping packet from=%s size=%zd (blacklisted)\n",
recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"skipping packet from=%s size=%zd (blacklisted)",
recv_sock->from_str, recv_sock->pkt_size);
return;
}

if (foreground)
printf("got v6 packet from=%s size=%zd\n", recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"got v6 packet from=%s size=%zd",
recv_sock->from_str, recv_sock->pkt_size);

list_for_each_entry(send_sock, &send_socks6, list) {
// do not repeat packet back to the same interface from which it originated
if (send_sock->ifindex == ifindex)
continue;

if (foreground)
printf("repeating data to %s\n", send_sock->ifname);
log_message(LOG_DEBUG, "repeating data to %s", send_sock->ifname);

// repeat data
sentsize = send_packet6(send_sock->sockfd, recv_sock->pkt_data, recv_sock->pkt_size);
Expand Down Expand Up @@ -980,29 +983,29 @@ repeat_packet4(struct recv_sock *recv_sock) {

if (!list_empty(&whitelisted_subnets) &&
!subnet_match(&recv_sock->from, &whitelisted_subnets)) {
if (foreground)
printf("skipping packet from=%s size=%zd (not whitelisted)\n",
recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"skipping packet from=%s size=%zd (not whitelisted)",
recv_sock->from_str, recv_sock->pkt_size);
return;
}

if (subnet_match(&recv_sock->from, &blacklisted_subnets)) {
if (foreground)
printf("skipping packet from=%s size=%zd (blacklisted)\n",
recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"skipping packet from=%s size=%zd (blacklisted)",
recv_sock->from_str, recv_sock->pkt_size);
return;
}

if (foreground)
printf("got v4 packet from=%s size=%zd\n", recv_sock->from_str, recv_sock->pkt_size);
log_message(LOG_DEBUG,
"got v4 packet from=%s size=%zd",
recv_sock->from_str, recv_sock->pkt_size);

list_for_each_entry(send_sock, &send_socks4, list) {
// do not repeat packet back to the same network from which it originated
if (same_network(&recv_sock->from, &send_sock->am))
continue;

if (foreground)
printf("repeating data to %s\n", send_sock->ifname);
log_message(LOG_DEBUG, "repeating data to %s", send_sock->ifname);

// repeat data
sentsize = send_packet4(send_sock->sockfd, recv_sock->pkt_data, recv_sock->pkt_size);
Expand Down