Print this page
OS-7667 IPFilter needs to keep and report state for cloud firewall logging
Portions contributed by: Mike Gerdts <mike.gerdts@joyent.com>
   1 /*
   2  * Copyright (C) 2002-2008 by Darren Reed.
   3  *
   4  * See the IPFILTER.LICENCE file for details on licencing.
   5  *
   6  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   7  * Use is subject to license terms.

   8  */
   9 
  10 #include <ctype.h>
  11 #include "ipf.h"
  12 #ifdef  IPFILTER_SCAN
  13 # include "netinet/ip_scan.h"
  14 #endif
  15 #include <sys/ioctl.h>
  16 #include <syslog.h>

  17 #ifdef  TEST_LEXER
  18 # define        NO_YACC
  19 union   {
  20         int             num;
  21         char            *str;
  22         struct in_addr  ipa;
  23         i6addr_t        ip6;

  24 } yylval;
  25 #endif
  26 #include "lexer.h"
  27 #include "y.tab.h"
  28 
  29 FILE *yyin;
  30 
  31 #define ishex(c)        (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || \
  32                          ((c) >= 'A' && (c) <= 'F'))
  33 #define TOOLONG         -3
  34 
  35 extern int      string_start;
  36 extern int      string_end;
  37 extern char     *string_val;
  38 extern int      pos;
  39 extern int      yydebug;
  40 
  41 char            *yystr = NULL;
  42 int             yytext[YYBUFSIZ+1];
  43 char            yychars[YYBUFSIZ+1];


 438                  * the code in inet_pton() anyway.
 439                  */
 440                 do {
 441                         *s++ = c;
 442                         c = yygetc(1);
 443                 } while ((ishex(c) || c == ':' || c == '.') &&
 444                          (s - ipv6buf < 46));
 445                 yyunputc(c);
 446                 *s = '\0';
 447 
 448                 if (inet_pton(AF_INET6, ipv6buf, &yylval.ip6) == 1) {
 449                         rval = YY_IPV6;
 450                         yyexpectaddr = 0;
 451                         goto done;
 452                 }
 453                 yypos = start;
 454                 c = oc;
 455         }
 456 #endif
 457 

































 458         if (c == ':') {
 459                 if (isbuilding == 1) {
 460                         yyunputc(c);
 461                         goto done;
 462                 }
 463                 rval = ':';
 464                 goto done;
 465         }
 466 
 467         if (isbuilding == 0 && c == '0') {
 468                 n = yygetc(0);
 469                 if (n == 'x') {
 470                         do {
 471                                 n = yygetc(1);
 472                         } while (ishex(n));
 473                         yyunputc(n);
 474                         rval = YY_HEX;
 475                         goto done;
 476                 }
 477                 yyunputc(n);


   1 /*
   2  * Copyright (C) 2002-2008 by Darren Reed.
   3  *
   4  * See the IPFILTER.LICENCE file for details on licencing.
   5  *
   6  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
   7  * Use is subject to license terms.
   8  * Copyright 2019 Joyent, Inc.
   9  */
  10 
  11 #include <ctype.h>
  12 #include "ipf.h"
  13 #ifdef  IPFILTER_SCAN
  14 # include "netinet/ip_scan.h"
  15 #endif
  16 #include <sys/ioctl.h>
  17 #include <syslog.h>
  18 #include <uuid/uuid.h>
  19 #ifdef  TEST_LEXER
  20 # define        NO_YACC
  21 union   {
  22         int             num;
  23         char            *str;
  24         struct in_addr  ipa;
  25         i6addr_t        ip6;
  26         uuid_t          uuid;
  27 } yylval;
  28 #endif
  29 #include "lexer.h"
  30 #include "y.tab.h"
  31 
  32 FILE *yyin;
  33 
  34 #define ishex(c)        (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || \
  35                          ((c) >= 'A' && (c) <= 'F'))
  36 #define TOOLONG         -3
  37 
  38 extern int      string_start;
  39 extern int      string_end;
  40 extern char     *string_val;
  41 extern int      pos;
  42 extern int      yydebug;
  43 
  44 char            *yystr = NULL;
  45 int             yytext[YYBUFSIZ+1];
  46 char            yychars[YYBUFSIZ+1];


 441                  * the code in inet_pton() anyway.
 442                  */
 443                 do {
 444                         *s++ = c;
 445                         c = yygetc(1);
 446                 } while ((ishex(c) || c == ':' || c == '.') &&
 447                          (s - ipv6buf < 46));
 448                 yyunputc(c);
 449                 *s = '\0';
 450 
 451                 if (inet_pton(AF_INET6, ipv6buf, &yylval.ip6) == 1) {
 452                         rval = YY_IPV6;
 453                         yyexpectaddr = 0;
 454                         goto done;
 455                 }
 456                 yypos = start;
 457                 c = oc;
 458         }
 459 #endif
 460 
 461         /*
 462          * UUID: 2426e38c-9f63-c0b8-cfd5-9aaeaf992d42 or uppercase
 463          */
 464         if (isbuilding == 0 && (ishex(c) || c == '-')) {
 465                 char uuidbuf[UUID_PRINTABLE_STRING_LENGTH], *s, oc;
 466                 int start;
 467 
 468                 start = yypos;
 469                 s = uuidbuf;
 470                 oc = c;
 471 
 472                 /*
 473                  * Don't worry about exact position of hexdigits and hyphens
 474                  * because uuid_parse() will provide the sanity check.
 475                  */
 476                 do {
 477                         *s++ = c;
 478                         c = yygetc(1);
 479                 } while ((ishex(c) || c == '-') &&
 480                     (s - uuidbuf < sizeof (uuidbuf)));
 481                 yyunputc(c);
 482                 *s = '\0';
 483 
 484                 if (uuid_parse(uuidbuf, yylval.uuid) == 0) {
 485                         rval = YY_UUID;
 486                         yyexpectaddr = 0;
 487                         goto done;
 488                 }
 489                 yypos = start;
 490                 c = oc;
 491         }
 492 
 493 
 494         if (c == ':') {
 495                 if (isbuilding == 1) {
 496                         yyunputc(c);
 497                         goto done;
 498                 }
 499                 rval = ':';
 500                 goto done;
 501         }
 502 
 503         if (isbuilding == 0 && c == '0') {
 504                 n = yygetc(0);
 505                 if (n == 'x') {
 506                         do {
 507                                 n = yygetc(1);
 508                         } while (ishex(n));
 509                         yyunputc(n);
 510                         rval = YY_HEX;
 511                         goto done;
 512                 }
 513                 yyunputc(n);