From: phk Date: Mon, 8 Sep 2008 14:30:31 +0000 (+0000) Subject: On platforms with multibyte sa_family and big endian, the compiled X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=014ad9a5b13e3d5704466dba3140ade2e77d082e;p=varnish On platforms with multibyte sa_family and big endian, the compiled ACLs would not work, as evidenced by #311. Add a log message for unknown sa_families, and use memmove to extract the sa_family member of the sockaddr into a suitably sized variable. Diagnosed by: Mithrandir Fixes: #311 git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3171 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvcl/vcc_acl.c b/varnish-cache/lib/libvcl/vcc_acl.c index 1b079b1e..6d0c748e 100644 --- a/varnish-cache/lib/libvcl/vcc_acl.c +++ b/varnish-cache/lib/libvcl/vcc_acl.c @@ -328,23 +328,37 @@ vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent, const char int depth, l, m, i; unsigned at[VRT_ACL_MAXADDR + 1]; const char *oc; + struct sockaddr sa; Fh(tl, 0, "\nstatic int\n"); Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", pfx, acln); Fh(tl, 0, "{\n"); - Fh(tl, 0, "\tunsigned fam;\n"); Fh(tl, 0, "\tconst unsigned char *a;\n"); + assert(sizeof (unsigned char) == 1); + assert(sizeof (unsigned short) == 2); + assert(sizeof (unsigned int) == 4); + if (sizeof sa.sa_family == 1) + Fh(tl, 0, "\tunsigned char fam;\n"); + else if (sizeof sa.sa_family == 2) + Fh(tl, 0, "\tunsigned short fam;\n"); + else if (sizeof sa.sa_family == 4) + Fh(tl, 0, "\tunsigned int fam;\n"); + else + assert(0 == __LINE__); + Fh(tl, 0, "\n"); Fh(tl, 0, "\ta = p;\n"); - Fh(tl, 0, "\tfam = a[%d];\n", offsetof(struct sockaddr, sa_family)); + Fh(tl, 0, "\tVRT_memmove(&fam, a + %d, sizeof fam);\n", + offsetof(struct sockaddr, sa_family)); Fh(tl, 0, "\tif (fam == %d)\n", PF_INET); Fh(tl, 0, "\t\ta += %d;\n", offsetof(struct sockaddr_in, sin_addr)); Fh(tl, 0, "\telse if (fam == %d)\n", PF_INET6); Fh(tl, 0, "\t\ta += %d;\n", offsetof(struct sockaddr_in6, sin6_addr)); - Fh(tl, 0, "\telse\n"); + Fh(tl, 0, "\telse {\n"); + Fh(tl, 0, "\t\tVRT_acl_log(sp, \"NO_FAM %s\");\n", acln); Fh(tl, 0, "\t\treturn(0);\n"); - Fh(tl, 0, "\n"); + Fh(tl, 0, "\t}\n\n"); depth = -1; oc = 0; at[0] = 256;