Skip to content

Commit 6f3bf58

Browse files
authored
Merge pull request #551 from jkroonza/dhcpv6relay
dhcpv6relay plugin from Jaco Kroon
2 parents fb769c3 + e648da5 commit 6f3bf58

12 files changed

Lines changed: 1354 additions & 116 deletions

File tree

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ AC_CONFIG_FILES([
330330
pppd/plugins/pppoatm/Makefile
331331
pppd/plugins/pppol2tp/Makefile
332332
pppd/plugins/radius/Makefile
333+
pppd/plugins/dhcpv6relay/Makefile
333334
pppdump/Makefile
334335
pppstats/Makefile
335336
scripts/Makefile

pppd/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pppd_SOURCES = \
8282
lcp.c \
8383
magic.c \
8484
main.c \
85+
event-handler.c \
8586
options.c \
8687
session.c \
8788
tty.c \

pppd/event-handler.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* event-handler.c - generic select() based event handler. Should be system
3+
* independent.
4+
*
5+
* Copyright (c) 1994-2025 Paul Mackerras. All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
*
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in
16+
* the documentation and/or other materials provided with the
17+
* distribution.
18+
*
19+
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
20+
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
21+
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
22+
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
24+
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
25+
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26+
*
27+
* Derived from sys-linux.c and sys-solaris.c by Jaco Kroon <jaco@uls.co.za>.
28+
*/
29+
#include <limits.h>
30+
#include <stddef.h>
31+
#include <errno.h>
32+
#include <sys/select.h>
33+
34+
#include "pppd.h"
35+
#include "pppd-private.h"
36+
37+
struct event_handler {
38+
struct event_handler* next;
39+
int fd;
40+
event_cb cb;
41+
void* ctx;
42+
};
43+
44+
static fd_set in_fds; /* set of fds that wait_input waits for */
45+
static int max_in_fd; /* highest fd set in in_fds */
46+
static struct event_handler* handlers;
47+
static int called_remove;
48+
49+
/********************************************************************
50+
*
51+
* wait_input - wait until there is data available,
52+
* for the length of time specified by *timo (indefinite
53+
* if timo is NULL).
54+
*/
55+
56+
void wait_input(struct timeval *timo)
57+
{
58+
fd_set ready, exc;
59+
int n;
60+
struct event_handler* h = handlers, *nh;
61+
62+
called_remove = 0;
63+
ready = in_fds;
64+
exc = in_fds;
65+
n = select(max_in_fd + 1, &ready, NULL, &exc, timo);
66+
if (n < 0 && errno != EINTR)
67+
fatal("select: %m");
68+
69+
while (h) {
70+
nh = h->next;
71+
if (FD_ISSET(h->fd, &ready)) {
72+
FD_CLR(h->fd, &ready); /* clear so that if we need to re-iterate we won't call again */
73+
h->cb(h->fd, h->ctx);
74+
75+
if (called_remove) {
76+
nh = handlers;
77+
called_remove = 0;
78+
}
79+
}
80+
h = nh;
81+
}
82+
}
83+
84+
/*
85+
* add_fd - add an fd to the set that wait_input waits for.
86+
*/
87+
void add_fd(int fd)
88+
{
89+
if (fd >= FD_SETSIZE)
90+
fatal("internal error: file descriptor too large (%d)", fd);
91+
FD_SET(fd, &in_fds);
92+
if (fd > max_in_fd)
93+
max_in_fd = fd;
94+
}
95+
96+
void add_fd_callback(int fd, event_cb cb, void* ctx)
97+
{
98+
struct event_handler *n = malloc(sizeof(*n));
99+
n->next = handlers;
100+
n->fd = fd;
101+
n->cb = cb;
102+
n->ctx = ctx;
103+
handlers = n;
104+
add_fd(fd);
105+
}
106+
107+
/*
108+
* remove_fd - remove an fd from the set that wait_input waits for.
109+
*/
110+
void remove_fd(int fd)
111+
{
112+
struct event_handler** h, *t;
113+
FD_CLR(fd, &in_fds);
114+
115+
for (h = &handlers; *h; h = &(*h)->next) {
116+
if (fd == (*h)->fd) {
117+
called_remove = 1;
118+
t = (*h)->next;
119+
free(*h);
120+
*h = t;
121+
return;
122+
}
123+
}
124+
}
125+
126+
void event_handler_init()
127+
{
128+
FD_ZERO(&in_fds);
129+
max_in_fd = 0;
130+
}

pppd/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ main(int argc, char *argv[])
497497
fd_devnull = i;
498498
}
499499

500+
event_handler_init();
501+
500502
/*
501503
* Initialize system-dependent stuff.
502504
*/

pppd/plugins/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ winbind_la_LDFLAGS = $(PLUGIN_LDFLAGS)
1717
winbind_la_SOURCES = winbind.c
1818

1919
if !SUNOS
20-
SUBDIRS = pppoe pppoatm pppol2tp radius
20+
SUBDIRS = pppoe pppoatm pppol2tp radius dhcpv6relay
2121
endif
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pppd_plugin_LTLIBRARIES = dhcpv6relay.la
2+
pppd_plugindir = $(PPPD_PLUGIN_DIR)
3+
4+
noinst_HEADERS = dhcpv6relay.h
5+
6+
dhcpv6relay_la_CPPFLAGS = -I${top_srcdir} -DSYSCONFDIR=\"${sysconfdir}\" -DPLUGIN
7+
dhcpv6relay_la_LDFLAGS = -module -avoid-version
8+
dhcpv6relay_la_SOURCES = dhcpv6relay.c

0 commit comments

Comments
 (0)