From nobody@FreeBSD.ORG Tue Jul 27 18:43:36 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 3ED8514CA7; Tue, 27 Jul 1999 18:43:36 -0700 (PDT)
Message-Id: <19990728014336.3ED8514CA7@hub.freebsd.org>
Date: Tue, 27 Jul 1999 18:43:36 -0700 (PDT)
From: ktsin@acm.org
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: [PATCH] Fix for "Proxy ARP"
X-Send-Pr-Version: www-1.0

>Number:         12847
>Category:       bin
>Synopsis:       [PATCH] Fix for "Proxy ARP"
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 27 18:50:00 PDT 1999
>Closed-Date:    Tue Sep 14 01:45:22 PDT 1999
>Last-Modified:  Tue Sep 14 01:48:18 PDT 1999
>Originator:     Key Teck Sin
>Release:        FreeBSD 3.2-STABLE
>Organization:
>Environment:
FreeBSD daffodil.singtel-yp.com 3.2-STABLE FreeBSD 3.2-STABLE #0: Sun Jul 18 15:45:00 SGT 1999     root@daffodil:/usr/src/sys/compile/DAFFODIL  i386
>Description:
See PR bin/12448.
>How-To-Repeat:
See PR bin/12448.
>Fix:
A buffer containing sockaddrs (RTA_DST, RTA_GATEWAY, RTA_NETMASK) 
is passed to and from the kernel. Arp did not align the sockaddrs
when constructing the buffer but the kernel (rtsock.c) required the
starting address of each sockaddr in the buffer to be a multiple of 4.

Arp -s broke when the size of sockaddr_dl (RTA_GATEWAY) increased from
20 to 54 after some new elements were added. So RTA_NETMASK was copied
to and from the wrong offset by rtsock.c (offset 16+56) and arp.c
(offset 16+54).

ROUNDUP() macro is now used in arp.c when copying sockaddr structures to
and from the buffer.

The patch is included below. Please fetch from
http://www.daddylonglegs.com/arp.patch if you encounter problems with
spaces, tabs and newlines.

==========================================cut here============================================
*** usr.sbin/arp/arp.c.orig     Sun Jun  6 10:26:08 1999
--- usr.sbin/arp/arp.c  Mon Jul 26 18:05:12 1999
***************
*** 112,117 ****
--- 112,120 ----

  #define SETFUNC(f)    { if (func) usage(); func = (f); }

+ #define ROUNDUP(a) \
+         ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
+
  int
  main(argc, argv)
        int argc;
***************
*** 494,504 ****
                printf(" published (proxy only)");
        if (rtm->rtm_addrs & RTA_NETMASK) {
                sin = (struct sockaddr_inarp *)
!                       (sdl->sdl_len + (char *)sdl);
                if (sin->sin_addr.s_addr == 0xffffffff)
                        printf(" published");
                if (sin->sin_len != 8)
!                       printf("(wierd)");
        }
          switch(sdl->sdl_type) {
              case IFT_ETHER:
--- 497,507 ----
                printf(" published (proxy only)");
        if (rtm->rtm_addrs & RTA_NETMASK) {
                sin = (struct sockaddr_inarp *)
!                       (ROUNDUP(sdl->sdl_len) + (char *)sdl);
                if (sin->sin_addr.s_addr == 0xffffffff)
                        printf(" published");
                if (sin->sin_len != 8)
!                       printf("(weird)");
        }
          switch(sdl->sdl_type) {
              case IFT_ETHER:
***************
*** 607,613 ****
        }
  #define NEXTADDR(w, s) \
        if (rtm->rtm_addrs & (w)) { \
!               bcopy((char *)&s, cp, sizeof(s)); cp += sizeof(s);}

        NEXTADDR(RTA_DST, sin_m);
        NEXTADDR(RTA_GATEWAY, sdl_m);
--- 610,616 ----
        }
  #define NEXTADDR(w, s) \
        if (rtm->rtm_addrs & (w)) { \
!               bcopy((char *)&s, cp, sizeof(s)); cp += ROUNDUP(sizeof(s));}

        NEXTADDR(RTA_DST, sin_m);
        NEXTADDR(RTA_GATEWAY, sdl_m);
============================================cut here========================================

>Release-Note:
>Audit-Trail:

From: "Jasper O'Malley" <jooji@neptune.oceancomputer.com>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/12847
Date: Fri, 10 Sep 1999 15:11:59 -0400 (EDT)

 Could someone please make sure the patch in this PR is committed before
 3.3 is released?
 
 
 
 
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Sep 13 09:23:05 PDT 1999 
Responsible-Changed-Why:  
Ruslan Ermilov is taking care of this. 
State-Changed-From-To: open->feedback 
State-Changed-By: ru 
State-Changed-When: Mon Sep 13 17:00:02 PDT 1999 
State-Changed-Why:  
Fixed in -current (arp.c,v 1.18). 
Awaiting approval from Jordan to MFC. 
State-Changed-From-To: feedback->closed 
State-Changed-By: ru 
State-Changed-When: Tue Sep 14 01:45:22 PDT 1999 
State-Changed-Why:  
Fixed in -stable (arp.c,v 1.14.2.4). 
>Unformatted:
