File Conn.c changed (mode: 100644) (index bee2aa8..db74d46) |
... |
... |
static void Conn_accept(const unsigned int slot) |
863 |
863 |
|
|
864 |
864 |
X->flags |= CONN_ADDR_LOCAL_DIRTY | CONN_ADDR_REMOTE_DIRTY; |
X->flags |= CONN_ADDR_LOCAL_DIRTY | CONN_ADDR_REMOTE_DIRTY; |
865 |
865 |
|
|
866 |
|
err = Conn_engine_add_obj(X); |
|
867 |
|
if (err != 0) { |
|
868 |
|
Conn_error_raise(slot, err); |
|
869 |
|
Conn_free_intern(X->slot); |
|
870 |
|
return; |
|
871 |
|
} |
|
|
866 |
|
if (Conns[slot].wp != NULL) { |
|
867 |
|
struct Conn_wpool *wp = Conns[slot].wp; |
|
868 |
|
struct Conn_wpool_worker *w = &wp->wi[0]; |
|
869 |
|
struct epoll_event ev; |
|
870 |
|
|
|
871 |
|
memset(&ev, 0, sizeof(struct epoll_event)); |
|
872 |
|
ev.events = X->events; |
|
873 |
|
ev.data.u32 = X->slot; |
|
874 |
|
err = epoll_ctl(w->epoll_fd, EPOLL_CTL_ADD, X->fd, &ev); |
|
875 |
|
if (err != 0) { |
|
876 |
|
Conn_error_raise(slot, err); |
|
877 |
|
Conn_free_intern(X->slot); |
|
878 |
|
return; |
|
879 |
|
} |
|
880 |
|
/* TODO: send signaling to thread to call accept callback */ |
|
881 |
|
/* TODO: maybe we want to pass the fd also by signaling channel */ |
|
882 |
|
} else { |
|
883 |
|
err = Conn_engine_add_obj(X); |
|
884 |
|
if (err != 0) { |
|
885 |
|
Conn_error_raise(slot, err); |
|
886 |
|
Conn_free_intern(X->slot); |
|
887 |
|
return; |
|
888 |
|
} |
872 |
889 |
|
|
873 |
|
if (Conns[slot].cb_accept) |
|
874 |
|
Conns[slot].cb_accept(X); |
|
875 |
|
else if (Conn_accept_cb != NULL) |
|
876 |
|
Conn_accept_cb(X); |
|
|
890 |
|
if (Conns[slot].cb_accept) |
|
891 |
|
Conns[slot].cb_accept(X); |
|
892 |
|
else if (Conn_accept_cb != NULL) |
|
893 |
|
Conn_accept_cb(X); |
|
894 |
|
} |
877 |
895 |
|
|
878 |
896 |
Conn_work_to_do++; |
Conn_work_to_do++; |
879 |
897 |
|
|
|
... |
... |
static void Conn_accept_allow(void) |
897 |
915 |
|
|
898 |
916 |
if (Conn_accept_is_allowed == 0) |
if (Conn_accept_is_allowed == 0) |
899 |
917 |
Conns[slot].events &= ~CONN_POLLIN; |
Conns[slot].events &= ~CONN_POLLIN; |
900 |
|
else |
|
|
918 |
|
else |
901 |
919 |
Conns[slot].events |= CONN_POLLIN; |
Conns[slot].events |= CONN_POLLIN; |
902 |
920 |
|
|
903 |
921 |
Conn_engine_chg_obj(&Conns[slot]); |
Conn_engine_chg_obj(&Conns[slot]); |
|
... |
... |
unsigned long long Conn_lifetime(struct Conn *C) |
1440 |
1458 |
|
|
1441 |
1459 |
return Conn_time_diff(&Conn_now, &Conns[slot].time_open); |
return Conn_time_diff(&Conn_now, &Conns[slot].time_open); |
1442 |
1460 |
} |
} |
|
1461 |
|
|
|
1462 |
|
/* |
|
1463 |
|
* Associate a Conn with a workers pool |
|
1464 |
|
*/ |
|
1465 |
|
void Conn_add_wp(struct Conn *C, struct Conn_wpool *wp) |
|
1466 |
|
{ |
|
1467 |
|
wp->users++; |
|
1468 |
|
C->wp = wp; |
|
1469 |
|
} |
|
1470 |
|
|
|
1471 |
|
/* |
|
1472 |
|
* Disassociate a Conn with a workers pool |
|
1473 |
|
*/ |
|
1474 |
|
void Conn_del_wp(struct Conn *C, struct Conn_wpool *wp) |
|
1475 |
|
{ |
|
1476 |
|
Conn_wpool_destroy(wp); |
|
1477 |
|
C->wp = NULL; |
|
1478 |
|
} |
File Conn.h changed (mode: 100644) (index e10421b..9823f64) |
2 |
2 |
#define _Conn_h 1 |
#define _Conn_h 1 |
3 |
3 |
|
|
4 |
4 |
#include <Conn_engine_core.h> |
#include <Conn_engine_core.h> |
|
5 |
|
#include <Conn_wpool.h> |
5 |
6 |
|
|
6 |
7 |
extern int Conn_engine_set(const unsigned int engine); |
extern int Conn_engine_set(const unsigned int engine); |
7 |
8 |
extern int Conn_init(const unsigned int max); |
extern int Conn_init(const unsigned int max); |
|
... |
... |
extern struct Conn *Conn_alloc(void); |
30 |
31 |
extern int Conn_commit(struct Conn *C); |
extern int Conn_commit(struct Conn *C); |
31 |
32 |
extern char *Conn_sys(void); |
extern char *Conn_sys(void); |
32 |
33 |
extern unsigned long long Conn_lifetime(struct Conn *C); |
extern unsigned long long Conn_lifetime(struct Conn *C); |
|
34 |
|
|
|
35 |
|
/* wpool */ |
|
36 |
|
extern void Conn_add_wp(struct Conn *C, struct Conn_wpool *wp); |
|
37 |
|
extern void Conn_del_wp(struct Conn *C, struct Conn_wpool *wp); |
33 |
38 |
#endif |
#endif |
File Conn_engine_core.h changed (mode: 100644) (index 1b67b22..18977aa) |
... |
... |
enum CONN_ERROR { |
70 |
70 |
#define CONN_FLAGS_CLOSE_AFTER_SEND 1 << 1 |
#define CONN_FLAGS_CLOSE_AFTER_SEND 1 << 1 |
71 |
71 |
#define CONN_ADDR_LOCAL_DIRTY 1 << 2 |
#define CONN_ADDR_LOCAL_DIRTY 1 << 2 |
72 |
72 |
#define CONN_ADDR_REMOTE_DIRTY 1 << 3 |
#define CONN_ADDR_REMOTE_DIRTY 1 << 3 |
|
73 |
|
#define CONN_ACCEPT_PENDING 1 << 4 |
73 |
74 |
|
|
74 |
75 |
/* Parameters */ |
/* Parameters */ |
75 |
76 |
enum CONN_PARA { |
enum CONN_PARA { |
|
... |
... |
struct Conn |
182 |
183 |
void (*cb_accept_error)(struct Conn *C); |
void (*cb_accept_error)(struct Conn *C); |
183 |
184 |
|
|
184 |
185 |
struct timeval time_open; /* When a connect succeded */ |
struct timeval time_open; /* When a connect succeded */ |
|
186 |
|
|
|
187 |
|
/* wpool */ |
|
188 |
|
struct Conn_wpool *wp; |
185 |
189 |
}; |
}; |
186 |
190 |
|
|
187 |
191 |
struct Conn_queue_entry |
struct Conn_queue_entry |
File Conn_engine_epoll.c changed (mode: 100644) (index 51e1c11..114f691) |
... |
... |
int Conn_epoll_chg_obj(struct Conn *C) |
154 |
154 |
* Returns: -1 on error, 0 nothing to do, n (>0) if some work was done |
* Returns: -1 on error, 0 nothing to do, n (>0) if some work was done |
155 |
155 |
* timeout is in 1/1000 seconds increments. |
* timeout is in 1/1000 seconds increments. |
156 |
156 |
*/ |
*/ |
157 |
|
int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot, |
|
158 |
|
const int revents)) |
|
|
157 |
|
int Conn_epoll_poll_core(int fd, struct epoll_event *ee, |
|
158 |
|
const unsigned int max, const int timeout2, |
|
159 |
|
void (*cb)(const unsigned int slot, const unsigned int revents)) |
159 |
160 |
{ |
{ |
160 |
161 |
int i, events; |
int i, events; |
161 |
162 |
unsigned int slot; |
unsigned int slot; |
162 |
163 |
|
|
163 |
164 |
Log(10, "%s: timeout2=%ums...\n", __FUNCTION__, timeout2); |
Log(10, "%s: timeout2=%ums...\n", __FUNCTION__, timeout2); |
164 |
165 |
again: |
again: |
165 |
|
events = epoll_wait(Conn_epoll_fd, Conn_epoll_events, Conn_no, timeout2); |
|
|
166 |
|
events = epoll_wait(fd, ee, max, timeout2); |
166 |
167 |
if ((events == -1) && (errno == EINTR)) |
if ((events == -1) && (errno == EINTR)) |
167 |
168 |
goto again; |
goto again; |
168 |
169 |
|
|
169 |
170 |
if (events < 0) { |
if (events < 0) { |
170 |
171 |
snprintf(Conn_error, sizeof(Conn_error), |
snprintf(Conn_error, sizeof(Conn_error), |
171 |
|
"%s: Conn_no=%d [%s]", |
|
172 |
|
__FUNCTION__, Conn_no, strerror(errno)); |
|
|
172 |
|
"%s: max=%d [%s]", |
|
173 |
|
__FUNCTION__, max, strerror(errno)); |
173 |
174 |
return -1; |
return -1; |
174 |
175 |
} |
} |
175 |
176 |
|
|
|
... |
... |
int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot, |
181 |
182 |
Log(11, "\tProcessing %d event(s)...\n", events); |
Log(11, "\tProcessing %d event(s)...\n", events); |
182 |
183 |
i = events - 1; |
i = events - 1; |
183 |
184 |
do { |
do { |
184 |
|
slot = Conn_epoll_events[i].data.u32; |
|
185 |
|
cb(slot, Conn_epoll_events[i].events); |
|
|
185 |
|
slot = ee[i].data.u32; |
|
186 |
|
cb(slot, ee[i].events); |
186 |
187 |
|
|
187 |
188 |
i--; |
i--; |
188 |
189 |
} while (i >= 0); |
} while (i >= 0); |
|
... |
... |
int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot, |
190 |
191 |
return events; |
return events; |
191 |
192 |
} |
} |
192 |
193 |
|
|
|
194 |
|
int Conn_epoll_poll(const int timeout2, |
|
195 |
|
void (*cb)(const unsigned int slot, const unsigned int events)) |
|
196 |
|
{ |
|
197 |
|
return Conn_epoll_poll_core(Conn_epoll_fd, Conn_epoll_events, Conn_no, timeout2, cb); |
|
198 |
|
} |
|
199 |
|
|
193 |
200 |
/* |
/* |
194 |
201 |
* Move a slot over an other. |
* Move a slot over an other. |
195 |
202 |
*/ |
*/ |
File Conn_engine_epoll.h changed (mode: 100644) (index b8597ef..5922a4e) |
... |
... |
extern int Conn_epoll_grow(unsigned int alloc); |
13 |
13 |
extern int Conn_epoll_add_obj(struct Conn *C); |
extern int Conn_epoll_add_obj(struct Conn *C); |
14 |
14 |
extern int Conn_epoll_del_obj(struct Conn *C); |
extern int Conn_epoll_del_obj(struct Conn *C); |
15 |
15 |
extern int Conn_epoll_chg_obj(struct Conn *C); |
extern int Conn_epoll_chg_obj(struct Conn *C); |
16 |
|
extern int Conn_epoll_poll(const int timeout2, void (*cb)(const unsigned int slot, |
|
17 |
|
const int revents)); |
|
|
16 |
|
extern int Conn_epoll_poll_core(const int fd, struct epoll_event *ee, |
|
17 |
|
const unsigned int max, const int timeout2, |
|
18 |
|
void (*cb)(const unsigned int slot, const unsigned int revents)); |
|
19 |
|
extern int Conn_epoll_poll(const int timeout2, |
|
20 |
|
void (*cb)(const unsigned int slot, const unsigned int revents)); |
18 |
21 |
extern int Conn_epoll_move_slot(const unsigned int dst, |
extern int Conn_epoll_move_slot(const unsigned int dst, |
19 |
22 |
const unsigned int src); |
const unsigned int src); |
20 |
23 |
|
|
File Makefile.in changed (mode: 100644) (index 3dca4a4..7c701fd) |
1 |
1 |
export CC := gcc |
export CC := gcc |
2 |
2 |
export INCS += -I. |
export INCS += -I. |
3 |
|
export LIBS += |
|
|
3 |
|
export LIBS += -lpthread |
4 |
4 |
export CFLAGS += -ggdb3 -Wall -Wextra -pedantic -Wno-long-long -pipe -fpic |
export CFLAGS += -ggdb3 -Wall -Wextra -pedantic -Wno-long-long -pipe -fpic |
5 |
|
export OBJS += Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o Conn.o |
|
|
5 |
|
export OBJS += Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o Conn.o \ |
|
6 |
|
Conn_wpool.o |
6 |
7 |
|
|
7 |
8 |
.PHONY: all |
.PHONY: all |
8 |
9 |
all: libConn.so.@VER@ |
all: libConn.so.@VER@ |
|
... |
... |
Conn_engine_poll.o: Conn_engine_poll.c Conn_config.h Conn_engine_core.h |
17 |
18 |
Conn_engine_epoll.o: Conn_engine_epoll.c Conn_config.h Conn_engine_core.h |
Conn_engine_epoll.o: Conn_engine_epoll.c Conn_config.h Conn_engine_core.h |
18 |
19 |
$(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c |
$(CC) $(CFLAGS) $(INCS) -c Conn_engine_epoll.c |
19 |
20 |
|
|
20 |
|
Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o |
|
|
21 |
|
Conn_wpool.o: Conn_wpool.c Conn_wpool.h Conn_engine_core.o Conn_config.h |
|
22 |
|
$(CC) $(CFLAGS) $(INCS) -c Conn_wpool.c |
|
23 |
|
|
|
24 |
|
Conn.o: Conn.c Conn.h Conn_engine_core.o Conn_engine_poll.o Conn_engine_epoll.o Conn_wpool.o |
21 |
25 |
$(CC) $(CFLAGS) $(INCS) -c Conn.c |
$(CC) $(CFLAGS) $(INCS) -c Conn.c |
22 |
26 |
|
|
23 |
27 |
%.o: %.c |
%.o: %.c |
File TODO changed (mode: 100644) (index 21c1e62..00f1837) |
19 |
19 |
[ ] Add a function to set the maximum number of connections. |
[ ] Add a function to set the maximum number of connections. |
20 |
20 |
[ ] Fix the whole list scanning for expiration, band and closing. |
[ ] Fix the whole list scanning for expiration, band and closing. |
21 |
21 |
[ ] Put callbacks in a structure to free some space from struct Conn. |
[ ] Put callbacks in a structure to free some space from struct Conn. |
|
22 |
|
[ ] wpool: When we free a Conn structure, we have to Conn_del_wp! |
|
23 |
|
|
22 |
24 |
[ ] Check if we are swapping and warn. |
[ ] Check if we are swapping and warn. |
23 |
25 |
[ ] Log faults and io. |
[ ] Log faults and io. |
24 |
26 |
[ ] We must have a single set of pointers to callback, not many. At Conn creation, |
[ ] We must have a single set of pointers to callback, not many. At Conn creation, |
|
29 |
31 |
Conn_ac_add(C, CONN_AC_ALLOW, "2001::1/64"); - for ipv6 |
Conn_ac_add(C, CONN_AC_ALLOW, "2001::1/64"); - for ipv6 |
30 |
32 |
Conn_ac_add(C, CONN_AC_ALLOW, "192.168.0.0/25"); - for ipv4 |
Conn_ac_add(C, CONN_AC_ALLOW, "192.168.0.0/25"); - for ipv4 |
31 |
33 |
[ ] A la redir stuff |
[ ] A la redir stuff |
|
34 |
|
|
32 |
35 |
[ ] Bridge 2 connections together for proxy stuff. |
[ ] Bridge 2 connections together for proxy stuff. |
33 |
36 |
[ ] Check PACKET: can we send with "send" without knowing the MAC? |
[ ] Check PACKET: can we send with "send" without knowing the MAC? |
34 |
37 |
[ ] UDP |
[ ] UDP |