home *** CD-ROM | disk | FTP | other *** search
/ ftp.ee.lbl.gov / 2014.05.ftp.ee.lbl.gov.tar / ftp.ee.lbl.gov / acld-1.11.tar.gz / acld-1.11.tar / acld-1.11 / acld.h < prev    next >
C/C++ Source or Header  |  2012-02-07  |  6KB  |  192 lines

  1. /* @(#) $Id: acld.h 806 2012-02-08 03:40:06Z leres $ (LBL) */
  2.  
  3. #include "cf.h"
  4. #include "io.h"
  5. #include "stats.h"
  6. #include "timer.h"
  7. #include "version.h"
  8.  
  9. /* acld states */
  10. enum acldstate {
  11.     ASTATE_NOTCONNECTED = 0,
  12.     ASTATE_CONNECTED,
  13.     ASTATE_LOGGEDIN,
  14.     ASTATE_SENTLOGIN,
  15.     ASTATE_SENTLISTACL,
  16.     ASTATE_SENTLISTROUTE,
  17.     ASTATE_READRESPONSE,
  18.     ASTATE_READERROR,
  19.     ASTATE_READACL,
  20.     ASTATE_READROUTE,
  21.     ASTATE_SENTATTR,
  22. };
  23.  
  24. /* Is it ok to handle a client request that requires router interaction? */
  25. #define OKTOBLOCK(p) \
  26.     ((p)->state == ASTATE_LOGGEDIN && \
  27.     (p)->sentattrs && (p)->listedroutes && (p)->listedallacls)
  28.  
  29. /* State */
  30. struct state {
  31.     enum acldstate state;        /* ASTATE_* */
  32.     const char *cmd;        /* command sent */
  33.     int s;                /* listen socket */
  34.     int ro;                /* listen socket (read only) */
  35.     int web;            /* listen socket (web registration) */
  36. #ifdef HAVE_BROCCOLI
  37.     int b;                /* listen socket (broccoli) */
  38. #endif
  39.     int rfd;            /* expect child read pipe */
  40.     int wfd;            /* expect child read pipe */
  41.     pid_t pid;            /* child pid */
  42.     u_int nclients;            /* next client number */
  43.  
  44.     int listedallacls;        /* have we listed all the acl's? */
  45.     int listedroutes;        /* have we listed the routes? */
  46.     int sentattrs;            /* have we sent the attributes? */
  47.  
  48.     struct route *routes;        /* list of routes from router */
  49.     size_t routeslen;        /* number of routes */
  50.     size_t routessize;        /* size of route array */
  51.  
  52.     int nullzerolen;        /* current number of nullzero routes */
  53.     struct stats nullzerostats;    /* nullzero statistics */
  54.  
  55.     struct timeval timeout;        /* select timeout */
  56.     struct iobuf rbuf;        /* child read buffer */
  57.     struct req *req;        /* linked list of server requests */
  58.     struct client *clients;        /* linked list of clients */
  59.     struct client *reqclient;    /* client we did the last request for */
  60.     struct cf *cf;            /* configuration */
  61.     struct timer t_ayt;        /* timer for "ayt" */
  62.     struct timer t_compact;        /* timer for "compact" */
  63.     struct timer t_login;        /* timer for next login attempt */
  64.     struct timer t_sync;        /* timer for next sync */
  65.  
  66.     void (*f_ayt)(struct state *);
  67.     void (*f_compact)(struct state *);
  68.     void (*f_droprestore)(struct state *, struct client *, struct req *);
  69.     void (*f_kill)(struct state *);
  70.     void (*f_listacl)(struct state *);
  71.     void (*f_listroute)(struct state *);
  72.     void (*f_login)(struct state *);
  73.     void (*f_nullzero)(struct state *, struct client *, struct req *);
  74.     void (*f_send)(struct state *, const char *, ...)
  75.         __attribute__ ((format (printf, 2, 3)));
  76.     void (*f_sendattr)(struct state *);
  77.     void (*f_sync)(struct state *);
  78. };
  79.  
  80. #include "acl.h"
  81. #include "util.h"
  82. #include "client.h"
  83.  
  84. #include "route.h"
  85. #include "whitelist.h"
  86.  
  87. /* Request types */
  88. enum reqtype {
  89.     REQ_UNKNOWN = 0,
  90.     REQ_RELOAD,        /* kill expect child process & reload config */
  91.     REQ_DROP,        /* block a host or subnet */
  92.     REQ_RESTORE,        /* unblock a host or subnet */
  93.     REQ_BLOCKHOSTHOST,    /* block a host to host pair */
  94.     REQ_RESTOREHOSTHOST,    /* unblock a host to host pair */
  95.     REQ_DROPUDPPORT,    /* block a udp port */
  96.     REQ_RESTOREUDPPORT,    /* unblock a udp port */
  97.     REQ_DROPTCPPORT,    /* block a tcp port */
  98.     REQ_RESTORETCPPORT,    /* unblock a tcp port */
  99.     REQ_PERMITUDPDSTHOSTPORT, /* permit udp dst-host/port */
  100.     REQ_UNPERMITUDPDSTHOSTPORT, /* remove permit udp dst-host/port */
  101.     REQ_PERMITTCPDSTHOSTPORT, /* permit tcp dst-host/port */
  102.     REQ_UNPERMITTCPDSTHOSTPORT, /* remove permit tcp dst-host/port */
  103.     REQ_DROPTCPDSTHOSTPORT,    /* block tcp dst-host/port */
  104.     REQ_RESTORETCPDSTHOSTPORT, /* remove tcp dst-host/port */
  105.     REQ_NULLZERO,        /* create null zero host route */
  106.     REQ_NONULLZERO,        /* remove null zero host route */
  107.     REQ_STATE,        /* display current acld state */
  108.     REQ_LISTACL,        /* list contains of specified acl */
  109.     REQ_LISTROUTE,        /* list routes */
  110.     REQ_WHITELIST,        /* list whitelist */
  111.     REQ_ADDWHITELIST,    /* add whitelist address */
  112.     REQ_REMWHITELIST,    /* remove whitelist address */
  113.     REQ_QUERY,        /* check host, host to host or subnet block */
  114.     REQ_QUERYNULLZERO,    /* check for a nullzero host route */
  115.     REQ_QUERYWHITELIST,    /* check for a whitelist host/net */
  116.     REQ_COMPACT,        /* schedule compaction of specified acl */
  117.     REQ_TEST,        /* (undocumented) */
  118.     REQ_EXIT,        /* terminate client session */
  119.     REQ_HELP,        /* display brief help message */
  120.     REQ_SYNC,        /* copy router config to nonvolatile memory */
  121.     REQ_AYT,        /* check that router is still alive */
  122. };
  123.  
  124. /* Request states */
  125. enum reqstate {
  126.     RSTATE_PENDING = 0,    /* not processed yet */
  127.     RSTATE_READCOMMENT,    /* reading client comments */
  128.     RSTATE_READRESPONSE,    /* reading child response */
  129.     RSTATE_CHILD,        /* waiting for child to reply */
  130.     RSTATE_DONE        /* ok to remove from queue */
  131. };
  132.  
  133. /* Request flags */
  134. #define RFLAG_CONTINUE    0x1    /* request had a comment */
  135. /* XXX change to RFLAG_COMMENT? */
  136. #define RFLAG_FAILED    0x2    /* request resulted in a failed status */
  137. #define RFLAG_IGNORE    0x4    /* request didn't result in any changes */
  138.  
  139. /* Request */
  140. struct req {
  141.     struct req *next;
  142.     enum reqtype type;        /* REQ_* */
  143.     enum reqstate state;        /* RSTATE_* */
  144.     int flags;            /* request flags */
  145.     const char *cmd;        /* client command name */
  146.     struct acllist *acllist;    /* acllist pointer */
  147.     char *aclname;            /* REQ_LISTACL ACL name */
  148.     u_int32_t cookie;
  149.     struct timeval ats;        /* arrival timestamp */
  150.     struct timeval cts;        /* completion timestamp */
  151.     struct acl acl;
  152.     struct route nullzero;
  153.     struct addr whitelist;
  154.     int an;                /* argument count */
  155.     char **av;            /* argument vector */
  156.     char *comment;
  157.     struct iobuf payload;
  158. };
  159.  
  160. #define LOGIN_SECS        15
  161. #define AYT_SECS        (10 * 60)
  162. #define SYNC_SECS        (30 * 60)
  163. #define SELECT_SECS        (10 * 60)
  164.  
  165. /* Must be greater than SELECT_SECS */
  166. #define IDLE_SECS        (2 * SELECT_SECS)
  167.  
  168. #define MAX_IPV4_WIDTH        16    /* widest IPv4 cidr block */
  169. #define MAX_IPV6_WIDTH        32    /* widest IPv6 cidr block */
  170.  
  171. #define DEFAULT_IPV4_WIDTH    24    /* default IPv4 cidr block width */
  172. #define DEFAULT_IPV6_WIDTH    64    /* default IPv6 cidr block width */
  173.  
  174. #include "util.h"
  175.  
  176. /* Globals */
  177. extern int debug;
  178. extern int verbose;
  179. extern int reload;
  180. extern const char *prog;
  181. extern struct s2v astate2str[];
  182. extern struct s2v rstate2str[];
  183. extern const char *configfn;
  184. extern const char *logfile;
  185. extern FILE *lf;
  186.  
  187. /* Functions */
  188. void appendreq(struct req **, struct req *) ;
  189. void freereq(struct req *);
  190. struct state *getstate(void);
  191. void nbio(int);
  192.