From owner-svn-src-head@FreeBSD.ORG Tue Mar 3 18:47:33 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7F2DE106568C; Tue, 3 Mar 2009 18:47:33 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6D0028FC08; Tue, 3 Mar 2009 18:47:33 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n23IlXcr018457; Tue, 3 Mar 2009 18:47:33 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n23IlX7N018454; Tue, 3 Mar 2009 18:47:33 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200903031847.n23IlX7N018454@svn.freebsd.org> From: Ed Schouten Date: Tue, 3 Mar 2009 18:47:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189315 - in head/sys/netgraph: . atm X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Mar 2009 18:47:34 -0000 Author: ed Date: Tue Mar 3 18:47:33 2009 New Revision: 189315 URL: http://svn.freebsd.org/changeset/base/189315 Log: Make Netgraph compile with Clang. Clang disallows structs with variable length arrays to be nested inside other structs, because this is in violation with ISO C99. Even though we can keep bugging the LLVM folks about this issue, we'd better just fix our code to not do this. This code seems to be the only code in the entire source tree that does this. I haven't tested this patch by using the kernel modules in question, but Diane Bruce and I have compared disassembled versions of these kernel modules. We would have expected them to be exactly the same, but due to randomness in the register allocator and reordering of instructions, there were some minor differences. Approved by: julian Modified: head/sys/netgraph/atm/ng_ccatm.h head/sys/netgraph/ng_pppoe.c head/sys/netgraph/ng_pppoe.h Modified: head/sys/netgraph/atm/ng_ccatm.h ============================================================================== --- head/sys/netgraph/atm/ng_ccatm.h Tue Mar 3 18:23:16 2009 (r189314) +++ head/sys/netgraph/atm/ng_ccatm.h Tue Mar 3 18:47:33 2009 (r189315) @@ -166,7 +166,6 @@ struct ngm_ccatm_portlist { struct ccatm_op { uint32_t op; /* request code */ - u_char data[]; }; #endif Modified: head/sys/netgraph/ng_pppoe.c ============================================================================== --- head/sys/netgraph/ng_pppoe.c Tue Mar 3 18:23:16 2009 (r189314) +++ head/sys/netgraph/ng_pppoe.c Tue Mar 3 18:47:33 2009 (r189315) @@ -290,7 +290,7 @@ static int pppoe_send_event(sessp sp, en static __inline const struct pppoe_tag* next_tag(const struct pppoe_hdr* ph) { - return (const struct pppoe_tag*)(((const char*)&ph->tag[0]) + return (const struct pppoe_tag*)(((const char*)(ph + 1)) + ntohs(ph->length)); } @@ -303,7 +303,7 @@ static const struct pppoe_tag* get_tag(const struct pppoe_hdr* ph, uint16_t idx) { const char *const end = (const char *)next_tag(ph); - const struct pppoe_tag *pt = &ph->tag[0]; + const struct pppoe_tag *pt = (const void *)(ph + 1); const char *ptn; /* @@ -381,7 +381,7 @@ make_packet(sessp sp) { ("%s: called from wrong state", __func__)); CTR2(KTR_NET, "%20s: called %d", __func__, sp->Session_ID); - dp = (char *)wh->ph.tag; + dp = (char *)(&wh->ph + 1); for (count = 0, tag = sp->neg->tags; ((count < sp->neg->numtags) && (count < NUMTAGS)); tag++, count++) { @@ -434,12 +434,12 @@ pppoe_match_svc(node_p node, const struc if (neg->service_len != ntohs(tag->tag_len)) continue; - if (strncmp(tag->tag_data, neg->service.data, + if (strncmp((const char *)(tag + 1), neg->service.data, ntohs(tag->tag_len)) == 0) break; } CTR3(KTR_NET, "%20s: matched %p for %s", __func__, - sp?sp->hook:NULL, tag->tag_data); + sp?sp->hook:NULL, (const char *)(tag + 1)); return (sp?sp->hook:NULL); } @@ -583,7 +583,7 @@ pppoe_finduniq(node_p node, const struct hook_p hook = NULL; union uniq uniq; - bcopy(tag->tag_data, uniq.bytes, sizeof(void *)); + bcopy(tag + 1, uniq.bytes, sizeof(void *)); /* Cycle through all known hooks. */ LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { /* Skip any nonsession hook. */ @@ -1100,7 +1100,7 @@ send_acname(sessp sp, const struct pppoe sts = (struct ngpppoe_sts *)msg->data; tlen = min(NG_HOOKSIZ - 1, ntohs(tag->tag_len)); - strncpy(sts->hook, tag->tag_data, tlen); + strncpy(sts->hook, (const char *)(tag + 1), tlen); sts->hook[tlen] = '\0'; NG_SEND_MSG_ID(error, NG_HOOK_NODE(sp->hook), msg, sp->creator, 0); @@ -1438,7 +1438,8 @@ ng_pppoe_rcvdata_ether(hook_p hook, item break; } if (neg->ac_name_len != htons(tag->tag_len) || - strncmp(neg->ac_name.data, tag->tag_data, + strncmp(neg->ac_name.data, + (const char *)(tag + 1), neg->ac_name_len) != 0) { break; } @@ -1767,10 +1768,10 @@ ng_pppoe_disconnect(hook_p hook) * Add a General error message and adjust * sizes. */ - tag = wh->ph.tag; + tag = (void *)(&wh->ph + 1); tag->tag_type = PTT_GEN_ERR; tag->tag_len = htons((u_int16_t)msglen); - strncpy(tag->tag_data, SIGNOFF, msglen); + strncpy((char *)(tag + 1), SIGNOFF, msglen); m->m_pkthdr.len = (m->m_len += sizeof(*tag) + msglen); wh->ph.length = htons(sizeof(*tag) + msglen); @@ -1859,7 +1860,7 @@ scan_tags(sessp sp, const struct pppoe_h { const char *const end = (const char *)next_tag(ph); const char *ptn; - const struct pppoe_tag *pt = &ph->tag[0]; + const struct pppoe_tag *pt = (const void *)(ph + 1); /* * Keep processing tags while a tag header will still fit. Modified: head/sys/netgraph/ng_pppoe.h ============================================================================== --- head/sys/netgraph/ng_pppoe.h Tue Mar 3 18:23:16 2009 (r189314) +++ head/sys/netgraph/ng_pppoe.h Tue Mar 3 18:47:33 2009 (r189315) @@ -201,7 +201,6 @@ struct ngpppoe_sts { struct pppoe_tag { u_int16_t tag_type; u_int16_t tag_len; - char tag_data[]; }__packed; struct pppoe_hdr{ @@ -210,7 +209,6 @@ struct pppoe_hdr{ u_int8_t code; u_int16_t sid; u_int16_t length; - struct pppoe_tag tag[]; }__packed;