[BACK]Return to npf_build.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.sbin / npf / npfctl

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.sbin/npf/npfctl/npf_build.c between version 1.51 and 1.52

version 1.51, 2019/08/08 21:29:15 version 1.52, 2019/09/29 18:51:08
Line 151  npfctl_debug_addif(const char *ifname)
Line 151  npfctl_debug_addif(const char *ifname)
         return 0;          return 0;
 }  }
   
 unsigned  nl_table_t *
 npfctl_table_getid(const char *name)  npfctl_table_getbyname(nl_config_t *ncf, const char *name)
 {  {
         unsigned tid = (unsigned)-1;  
         nl_iter_t i = NPF_ITER_BEGIN;          nl_iter_t i = NPF_ITER_BEGIN;
         nl_table_t *tl;          nl_table_t *tl;
   
         /* XXX dynamic ruleset */          /* XXX dynamic ruleset */
         if (!npf_conf) {          if (!ncf) {
                 return (unsigned)-1;                  return NULL;
         }          }
         while ((tl = npf_table_iterate(npf_conf, &i)) != NULL) {          while ((tl = npf_table_iterate(ncf, &i)) != NULL) {
                 const char *tname = npf_table_getname(tl);                  const char *tname = npf_table_getname(tl);
                 if (strcmp(tname, name) == 0) {                  if (strcmp(tname, name) == 0) {
                         tid = npf_table_getid(tl);  
                         break;                          break;
                 }                  }
         }          }
         return tid;          return tl;
   }
   
   unsigned
   npfctl_table_getid(const char *name)
   {
           nl_table_t *tl;
   
           tl = npfctl_table_getbyname(npf_conf, name);
           return tl ? npf_table_getid(tl) : (unsigned)-1;
 }  }
   
 const char *  const char *
Line 873  npfctl_build_natseg(int sd, int type, un
Line 880  npfctl_build_natseg(int sd, int type, un
  * npfctl_fill_table: fill NPF table with entries from a specified file.   * npfctl_fill_table: fill NPF table with entries from a specified file.
  */   */
 static void  static void
 npfctl_fill_table(nl_table_t *tl, u_int type, const char *fname)  npfctl_fill_table(nl_table_t *tl, u_int type, const char *fname, FILE *fp)
 {  {
         char *buf = NULL;          char *buf = NULL;
         int l = 0;          int l = 0;
         FILE *fp;  
         size_t n;          size_t n;
   
         fp = fopen(fname, "r");          if (fp == NULL && (fp = fopen(fname, "r")) == NULL) {
         if (fp == NULL) {  
                 err(EXIT_FAILURE, "open '%s'", fname);                  err(EXIT_FAILURE, "open '%s'", fname);
         }          }
         while (l++, getline(&buf, &n, fp) != -1) {          while (l++, getline(&buf, &n, fp) != -1) {
Line 908  npfctl_fill_table(nl_table_t *tl, u_int 
Line 913  npfctl_fill_table(nl_table_t *tl, u_int 
 }  }
   
 /*  /*
    * npfctl_load_table: create an NPF table and fill with contents from a file.
    */
   nl_table_t *
   npfctl_load_table(const char *tname, int tid, u_int type,
       const char *fname, FILE *fp)
   {
           nl_table_t *tl;
   
           tl = npf_table_create(tname, tid, type);
           if (tl && fname) {
                   npfctl_fill_table(tl, type, fname, fp);
           }
   
           return tl;
   }
   
   /*
  * npfctl_build_table: create an NPF table, add to the configuration and,   * npfctl_build_table: create an NPF table, add to the configuration and,
  * if required, fill with contents from a file.   * if required, fill with contents from a file.
  */   */
Line 916  npfctl_build_table(const char *tname, u_
Line 938  npfctl_build_table(const char *tname, u_
 {  {
         nl_table_t *tl;          nl_table_t *tl;
   
         tl = npf_table_create(tname, npfctl_tid_counter++, type);          if (type == NPF_TABLE_CONST && !fname) {
         assert(tl != NULL);  
   
         if (fname) {  
                 npfctl_fill_table(tl, type, fname);  
         } else if (type == NPF_TABLE_CONST) {  
                 yyerror("table type 'const' must be loaded from a file");                  yyerror("table type 'const' must be loaded from a file");
         }          }
   
           tl = npfctl_load_table(tname, npfctl_tid_counter++, type, fname, NULL);
           assert(tl != NULL);
   
         if (npf_table_insert(npf_conf, tl)) {          if (npf_table_insert(npf_conf, tl)) {
                 yyerror("table '%s' is already defined", tname);                  yyerror("table '%s' is already defined", tname);
         }          }

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52

CVSweb <webmaster@jp.NetBSD.org>