1 /*! \file
2  * Main functions to set-up dpi information and to initialise sockets
3  */
4 
5 #ifndef DPID_H
6 #define DPID_H
7 
8 #include <sys/socket.h>
9 #include <sys/select.h>   /* for fd_set */
10 #include <sys/un.h>
11 #include <signal.h>       /* for sig_atomic_t */
12 #include <netinet/in.h>   /* for ntohl, IPPORT_USERRESERVED and stuff */
13 
14 #include "d_size.h"
15 
16 /* FreeBSD 6.4 doesn't have it */
17 #ifndef IPPORT_USERRESERVED
18  #define IPPORT_USERRESERVED 5000
19 #endif
20 
21 #define PATH_LEN 50
22 #define CMDLEN 20
23 #define MSGLEN 50
24 #define DPID_BASE_PORT (IPPORT_USERRESERVED + 20)
25 
26 /*! \TODO: Should read this from dillorc */
27 #define SRS_NAME "dpid.srs"
28 char *srs_name;
29 
30 /*! dpid's service request socket file descriptor */
31 int srs_fd;
32 
33 /*! plugin state information
34  */
35 struct dp {
36    char *id;
37    char *path;
38    int sock_fd;
39    int port;
40    pid_t pid;
41    int filter;
42 };
43 
44 /*! bind dpi with service
45  */
46 struct service {
47    char *name;
48    int dp_index;
49 };
50 
51 /*! Number of available plugins */
52 int numdpis;
53 
54 /*! Number of sockets being watched */
55 int numsocks;
56 
57 /*! State information for each plugin. */
58 struct dp *dpi_attr_list;
59 
60 /*! service served for each plugin  */
61 Dlist *services_list;
62 
63 /*! Set of sockets watched for connections */
64 fd_set sock_set;
65 
66 /*! Set to 1 by the SIGCHLD handler dpi_sigchld */
67 extern volatile sig_atomic_t caught_sigchld;
68 
69 void rm_dpi_sockets(struct dp *dpi_attr_list, int numdpis);
70 
71 void cleanup();
72 
73 void free_dpi_attr(struct dp *dpi_attr);
74 
75 void free_plugin_list(struct dp **dpi_attr_list_ptr, int numdpis);
76 
77 void free_services_list(Dlist *s_list);
78 
79 enum file_type get_file_type(char *file_name);
80 
81 int get_dpi_attr(char *dpi_dir, char *service, struct dp *dpi_attr);
82 
83 int register_service(struct dp *dpi_attr, char *service);
84 
85 int register_all(struct dp **attlist);
86 
87 int fill_services_list(struct dp *attlist, int numdpis, Dlist **services_list);
88 
89 int init_ids_srs_socket();
90 
91 int init_dpi_socket(struct dp *dpi_attr);
92 
93 int init_all_dpi_sockets(struct dp *dpi_attr_list);
94 
95 void dpi_sigchld(int sig);
96 
97 void handle_sigchld(void);
98 
99 void est_dpi_sigchld(void);
100 
101 void est_dpi_terminator(void);
102 
103 void stop_active_dpis(struct dp *dpi_attr_list, int numdpis);
104 
105 void ignore_dpi_sockets(struct dp *dpi_attr_list, int numdpis);
106 
107 int register_all_cmd();
108 
109 char *get_message(int sock, char *dpi_tag);
110 
111 int service_match(const struct service *A, const char *B);
112 
113 void send_sockport(int sock_fd, char * dpi_tag, struct dp *dpi_attr_list);
114 
115 #endif
116