1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* (C) 2009 by Pablo Neira Ayuso <pablo@netfilter.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdlib.h>
#include "channel.h"
#include "network.h"
struct multichannel *
multichannel_open(struct channel_conf *conf, int len)
{
struct multichannel *m;
int i, set_default_channel = 0;
if (len <= 0 || len > MULTICHANNEL_MAX)
return NULL;
m = calloc(sizeof(struct multichannel), 1);
if (m == NULL)
return NULL;
m->channel_num = len;
for (i = 0; i < len; i++) {
m->channel[i] = channel_open(&conf[i]);
if (m->channel[i] == NULL) {
int j;
for (j=0; j<i; j++) {
channel_close(m->channel[j]);
}
free(m);
return NULL;
}
if (conf[i].channel_flags & CHANNEL_F_DEFAULT) {
m->current = m->channel[i];
set_default_channel = 1;
}
}
if (!set_default_channel)
m->current = m->channel[0];
return m;
}
int multichannel_send(struct multichannel *c, const struct nethdr *net)
{
return channel_send(c->current, net);
}
int multichannel_send_flush(struct multichannel *c)
{
return channel_send_flush(c->current);
}
int multichannel_recv(struct multichannel *c, char *buf, int size)
{
return channel_recv(c->current, buf, size);
}
void multichannel_close(struct multichannel *m)
{
int i;
for (i = 0; i < m->channel_num; i++) {
channel_close(m->channel[i]);
}
free(m);
}
void multichannel_stats(struct multichannel *m, int fd)
{
channel_stats(m->current, fd);
}
void
multichannel_stats_extended(struct multichannel *m,
struct nlif_handle *h, int fd)
{
int i, active;
for (i = 0; i < m->channel_num; i++) {
if (m->current == m->channel[i]) {
active = 1;
} else {
active = 0;
}
channel_stats_extended(m->channel[i], active, h, fd);
}
}
int multichannel_get_ifindex(struct multichannel *m, int i)
{
return m->channel[i]->channel_ifindex;
}
int multichannel_get_current_ifindex(struct multichannel *m)
{
return m->current->channel_ifindex;
}
void multichannel_set_current_channel(struct multichannel *m, int i)
{
m->current = m->channel[i];
}
void multichannel_change_current_channel(struct multichannel *m, int i)
{
if (m->current != m->channel[i])
m->current = m->channel[i];
}
|