This diff adds dhcrelay support for replacing Relay Agent Information
on incoming packets with our configuration. This might be useful if you
want to override user sent information or to adapt the incoming packet to
another network.

ok?

Index: dhcrelay.8
===================================================================
RCS file: /home/obsdcvs/src/usr.sbin/dhcrelay/dhcrelay.8,v
retrieving revision 1.14
diff -u -p -r1.14 dhcrelay.8
--- dhcrelay.8  13 Dec 2016 06:55:32 -0000      1.14
+++ dhcrelay.8  15 Dec 2016 13:37:47 -0000
@@ -44,7 +44,7 @@
 .Nd Dynamic Host Configuration Protocol relay agent
 .Sh SYNOPSIS
 .Nm
-.Op Fl do
+.Op Fl dor
 .Op Fl C Ar circuit-id
 .Op Fl R Ar remote-id
 .Fl i Ar interface
@@ -118,6 +118,8 @@ relay agent information sub-option value
 .Nm
 should append on relayed packets.
 If this option is not specified it will use the destination address by default.
+.It Fl r
+Allow replacing incoming Relay Agent Information with the one configured.
 .El
 .Sh SEE ALSO
 .Xr dhclient 8 ,
Index: dhcrelay.c
===================================================================
RCS file: /home/obsdcvs/src/usr.sbin/dhcrelay/dhcrelay.c,v
retrieving revision 1.54
diff -u -p -r1.54 dhcrelay.c
--- dhcrelay.c  13 Dec 2016 17:40:41 -0000      1.54
+++ dhcrelay.c  15 Dec 2016 13:37:47 -0000
@@ -94,6 +94,7 @@ int oflag;
 enum dhcp_relay_mode    drm = DRM_UNKNOWN;
 const char             *rai_circuit = NULL;
 const char             *rai_remote = NULL;
+int                     rai_replace = 0;
 
 struct server_list {
        struct interface_info *intf;
@@ -118,7 +119,7 @@ main(int argc, char *argv[])
        openlog(__progname, LOG_NDELAY, DHCPD_LOG_FACILITY);
        setlogmask(LOG_UPTO(LOG_INFO));
 
-       while ((ch = getopt(argc, argv, "aC:di:oR:")) != -1) {
+       while ((ch = getopt(argc, argv, "aC:di:oR:r")) != -1) {
                switch (ch) {
                case 'C':
                        rai_circuit = optarg;
@@ -141,6 +142,9 @@ main(int argc, char *argv[])
                case 'R':
                        rai_remote = optarg;
                        break;
+               case 'r':
+                       rai_replace = 1;
+                       break;
 
                default:
                        usage();
@@ -444,7 +448,7 @@ usage(void)
 {
        extern char     *__progname;
 
-       fprintf(stderr, "usage: %s [-do] [-C circuit-id] [-R remote-id] "
+       fprintf(stderr, "usage: %s [-dor] [-C circuit-id] [-R remote-id] "
            "-i interface\n\tdestination ...\n",
            __progname);
        exit(1);
@@ -675,8 +679,12 @@ relay_agentinfo_append(struct packet_ctx
                }
 
                if (*p == DHO_RELAY_AGENT_INFORMATION) {
-                       hasinfo = 1;
-                       continue;
+                       if (rai_replace) {
+                               memmove(p, p + optlen, opttotal - i);
+                               opttotal -= optlen;
+                               optlen = 0;
+                       } else
+                               hasinfo = 1;
                }
 
                p += optlen;

Reply via email to