Subject: bin/3462: sizeof(struct llc) varries from port to port
To: None <gnats-bugs@gnats.netbsd.org, wrstuden@loki.stanford.edu>
From: None <wrstuden@loki.stanford.edu>
List: netbsd-bugs
Date: 04/07/1997 21:28:26
>Number:         3462
>Category:       bin
>Synopsis:       sizeof(struct llc) returns 10 on mac68k, and needs to be 8
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr  7 21:35:00 1997
>Last-Modified:
>Originator:     William Studenmund
>Organization:
	
>Release:        1.2
>Environment:
mac68k, NetBSD 1.2	
System: NetBSD pokey 1.2 NetBSD 1.2 (POKEY) #116: Sun Feb 23 21:16:25 PST 1997 croot@pokey:/y1/src12.current/sys/arch/mac68k/compile/POKEY mac68k


>Description:
For some reason, sizeof(struct llc) returns 10 on mac68k (and I'd
assume all other m68k ports) and 8 on port-i386. Looking at the
struct, it should be 8. The problem is that various parts of the
networking code want to prepend llc headers, and prepend a buffer
of sizeof(struct llc). Netatalk wanted to (and really aught be able
to), and net/if_fddisubr.c also wants to.

This bug kept netatalk from running on a mac until all such references were
manually changed to "8". Then it worked.

I've tried this both under gcc 2.7.2 and gcc 2.7.2.1 (on an OpenBSD system,
but they try to track us on these things, I thought).

If I comment out the type_frmr variant of struct llc, then everything
compiles fine and sizeof(struct llc) is 8.

>How-To-Repeat:
I'm including a shell archive Christos sent me. It prints out
"10" on the two gcc's above. I'm not sure why the #pragma pack(1)'s
are wrapped in #if's. I get the same results even if I delete the #if's.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	test.c
#	if_llc.h
#
echo x - test.c
sed 's/^X//' >test.c << 'END-of-test.c'
X#include <stdio.h>
X#include <sys/types.h>
X#include "if_llc.h"
X
Xmain()
X{
X	printf("%d\n", sizeof(struct llc));
X}
END-of-test.c
echo x - if_llc.h
sed 's/^X//' >if_llc.h << 'END-of-if_llc.h'
X/*	$NetBSD: if_llc.h,v 1.6 1995/03/08 02:56:57 cgd Exp $	*/
X
X/*
X * Copyright (c) 1988, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X *	@(#)if_llc.h	8.1 (Berkeley) 6/10/93
X */
X
X/*
X * IEEE 802.2 Link Level Control headers, for use in conjunction with
X * 802.{3,4,5} media access control methods.
X *
X * Headers here do not use bit fields due to shortcommings in many
X * compilers.
X */
X
X#if __GNUC__ == 2 && __GNUC_MINOR__ < 7 
X#pragma pack(1)
X#endif
X
Xstruct llc {
X	u_int8_t llc_dsap;
X	u_int8_t llc_ssap;
X	union {
X	    struct {
X		u_int8_t control;
X		u_int8_t format_id;
X		u_int8_t class;
X		u_int8_t window_x2;
X	    } type_u;
X	    struct {
X		u_int8_t num_snd_x2;
X		u_int8_t num_rcv_x2;
X	    } type_i;
X	    struct {
X		u_int8_t control;
X		u_int8_t num_rcv_x2;
X	    } type_s;
X	    struct {
X	        u_int8_t control;
X		struct frmrinfo {
X			u_int8_t rej_pdu_0;
X			u_int8_t rej_pdu_1;
X			u_int8_t frmr_control;
X			u_int8_t frmr_control_ext;
X			u_int8_t frmr_cause;
X		} frmrinfo;
X	    } type_frmr;
X	    struct {
X		u_int8_t  control;
X		u_int8_t  org_code[3];
X		u_int16_t ether_type;
X	    } type_snap;
X	    struct {
X		u_int8_t control;
X		u_int8_t control_ext;
X	    } type_raw;
X	} llc_un;
X} __attribute__((packed));
X
X#if __GNUC__ == 2 && __GNUC_MINOR__ < 7 
X#pragma pack(4)
X#endif
X
X#define llc_control            llc_un.type_u.control
X#define	llc_control_ext        llc_un.type_raw.control_ext
X#define llc_fid                llc_un.type_u.format_id
X#define llc_class              llc_un.type_u.class
X#define llc_window             llc_un.type_u.window_x2
X#define llc_frmrinfo           llc_un.type_frmr.frmrinfo
X#define llc_frmr_pdu0          llc_un.type_frmr.frmrinfo.rej_pdu0
X#define llc_frmr_pdu1          llc_un.type_frmr.frmrinfo.rej_pdu1
X#define llc_frmr_control       llc_un.type_frmr.frmrinfo.frmr_control
X#define llc_frmr_control_ext   llc_un.type_frmr.frmrinfo.frmr_control_ext
X#define llc_frmr_cause         llc_un.type_frmr.frmrinfo.frmr_control_ext
X
X/*
X * Don't use sizeof(struct llc_un) for LLC header sizes
X */
X#define LLC_ISFRAMELEN 4
X#define LLC_UFRAMELEN  3
X#define LLC_FRMRLEN    7
X
X/*
X * Unnumbered LLC format commands
X */
X#define LLC_UI		0x3
X#define LLC_UI_P	0x13
X#define LLC_DISC	0x43
X#define	LLC_DISC_P	0x53
X#define LLC_UA		0x63
X#define LLC_UA_P	0x73
X#define LLC_TEST	0xe3
X#define LLC_TEST_P	0xf3
X#define LLC_FRMR	0x87
X#define	LLC_FRMR_P	0x97
X#define LLC_DM		0x0f
X#define	LLC_DM_P	0x1f
X#define LLC_XID		0xaf
X#define LLC_XID_P	0xbf
X#define LLC_SABME	0x6f
X#define LLC_SABME_P	0x7f
X
X/*
X * Supervisory LLC commands
X */
X#define	LLC_RR		0x01
X#define	LLC_RNR		0x05
X#define	LLC_REJ		0x09
X
X/*
X * Info format - dummy only
X */
X#define	LLC_INFO	0x00
X
X/*
X * ISO PDTR 10178 contains among others
X */
X#define LLC_X25_LSAP	0x7e
X#define LLC_SNAP_LSAP	0xaa
X#define LLC_ISO_LSAP	0xfe
END-of-if_llc.h
exit


>Fix:
I wish I knew!
>Audit-Trail:
>Unformatted: