~ubuntu-branches/ubuntu/wily/ntopng/wily-proposed

« back to all changes in this revision

Viewing changes to nDPI/src/lib/protocols/sopcast.c

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2014-07-27 16:13:47 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140727161347-0i8n5upu69ibq5d2
Tags: 1.2.0+dfsg1-1
* Imported Upstream version 1.2.0+dfsg1
* Update watch rule for new upstream naming convention.
* get-roig-source: Support both +svn and ~svn in version.
* Remove external hiredis from orig tarball.
* Remove Rickshaw from orig tarball.
* Remove documentation without source from orig tarball and insert an http
* Remove corrupted unused serializeCFJSON-0.1.js from orig tarball.
  link to it in README.Debian.
* Remove nDPI from orig tarball.
* Remove all debian/missing-sources files that are now included not-minified
  by upstream. Remove build-deps on node-uglify and cleancss.
* Remove references to third-party/redis-lua (removed upstream).
* Update copyright.
* Refresh patches and remove those merged upstream.
* Add external-hiredis.patch to use system libhiredis.
* Add rickshaw-keep-one.patch to remove references to additional rickshaw
  library.
* Add no-svn.patch to drop requirement on SVN.
* Add manpage.patch to fix usage of minus signs, hyphens, and dashes,
  missing space and line breaks.
* Add rickshaw.patch to use single rickshaw.{css,js} files.
* Split library removing part of build-flags.patch into remove-libs.patch.
* Rename debian-defaults.patch to path-defaults.patch and use installation
  path from configure.
* Use dh-autoreconf instead of autotools-dev.
* Add build-dep on libsqlite3-dev.
* Update build-dep on newer libndpi-dev.
* Cleanup of dh_install rules.
* Fix typo in font-awesome symlink path and remove and updates symlink links
  in ntopng-data/
* Remove executable bit to non executable files.
* Use system linjs-jquery tablesorter and form.
* Add Build-Dep on libhiredis-dev.
* Remove empty httpdocs/ssl directory.
* Add systemd support.
* Stop supporting ENABLED in /etc/default/ntopng and debian/NEWS to notify
  users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * sopcast.c
3
 
 *
4
 
 * Copyright (C) 2009-2011 by ipoque GmbH
5
 
 * Copyright (C) 2011-13 - ntop.org
6
 
 *
7
 
 * This file is part of nDPI, an open source deep packet inspection
8
 
 * library based on the OpenDPI and PACE technology by ipoque GmbH
9
 
 *
10
 
 * nDPI is free software: you can redistribute it and/or modify
11
 
 * it under the terms of the GNU Lesser General Public License as published by
12
 
 * the Free Software Foundation, either version 3 of the License, or
13
 
 * (at your option) any later version.
14
 
 *
15
 
 * nDPI is distributed in the hope that it will be useful,
16
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU Lesser General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU Lesser General Public License
21
 
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
22
 
 * 
23
 
 */
24
 
 
25
 
 
26
 
#include "ndpi_protocols.h"
27
 
 
28
 
#ifdef NDPI_PROTOCOL_SOPCAST
29
 
 
30
 
 
31
 
static void ndpi_int_sopcast_add_connection(struct ndpi_detection_module_struct
32
 
                                                                                          *ndpi_struct, struct ndpi_flow_struct *flow)
33
 
{
34
 
        ndpi_int_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SOPCAST, NDPI_REAL_PROTOCOL);
35
 
}
36
 
 
37
 
/**
38
 
 * this function checks for sopcast tcp pattern
39
 
 *
40
 
 * NOTE: if you add more patterns please keep the number of if levels
41
 
 * low, it is already complex enough
42
 
 */
43
 
        
44
 
#if !defined(WIN32)
45
 
 static inline
46
 
#else
47
 
__forceinline static
48
 
#endif
49
 
         u_int8_t ndpi_int_is_sopcast_tcp(const u_int8_t * payload, const u_int16_t payload_len)
50
 
{
51
 
        if (payload_len != 54)
52
 
                return 0;
53
 
 
54
 
        if (payload[2] != payload[3] - 4 && payload[2] != payload[3] + 4)
55
 
                return 0;
56
 
 
57
 
        if (payload[2] != payload[4] - 1 && payload[2] != payload[4] + 1)
58
 
                return 0;
59
 
 
60
 
        if (payload[25] != payload[25 + 16 - 1] + 1 && payload[25] != payload[25 + 16 - 1] - 1) {
61
 
 
62
 
                if (payload[3] != payload[25] &&
63
 
                        payload[3] != payload[25] - 4 && payload[3] != payload[25] + 4 && payload[3] != payload[25] - 21) {
64
 
                        return 0;
65
 
                }
66
 
        }
67
 
 
68
 
        if (payload[4] != payload[28] ||
69
 
                payload[28] != payload[30] ||
70
 
                payload[30] != payload[31] ||
71
 
                get_u_int16_t(payload, 30) != get_u_int16_t(payload, 32) || get_u_int16_t(payload, 32) != get_u_int16_t(payload, 34)) {
72
 
 
73
 
                if ((payload[2] != payload[5] - 1 && payload[2] != payload[5] + 1) ||
74
 
                        payload[2] != payload[25] ||
75
 
                        payload[4] != payload[28] ||
76
 
                        payload[4] != payload[31] ||
77
 
                        payload[4] != payload[32] ||
78
 
                        payload[4] != payload[33] ||
79
 
                        payload[4] != payload[34] ||
80
 
                        payload[4] != payload[35] || payload[4] != payload[30] || payload[2] != payload[36]) {
81
 
                        return 0;
82
 
                }
83
 
        }
84
 
 
85
 
        if (payload[42] != payload[53])
86
 
                return 0;
87
 
 
88
 
        if (payload[45] != payload[46] + 1 && payload[45] != payload[46] - 1)
89
 
                return 0;
90
 
 
91
 
        if (payload[45] != payload[49] || payload[46] != payload[50] || payload[47] != payload[51])
92
 
                return 0;
93
 
 
94
 
        return 1;
95
 
}
96
 
 
97
 
static void ndpi_search_sopcast_tcp(struct ndpi_detection_module_struct
98
 
                                                                          *ndpi_struct, struct ndpi_flow_struct *flow)
99
 
{
100
 
 
101
 
        struct ndpi_packet_struct *packet = &flow->packet;
102
 
        
103
 
        if (flow->packet_counter == 1 && packet->payload_packet_len == 54 && get_u_int16_t(packet->payload, 0) == ntohs(0x0036)) {
104
 
                if (ndpi_int_is_sopcast_tcp(packet->payload, packet->payload_packet_len)) {
105
 
                        NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast TCP \n");
106
 
                        ndpi_int_sopcast_add_connection(ndpi_struct, flow);
107
 
                        return;
108
 
                }
109
 
        }
110
 
 
111
 
        NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "exclude sopcast TCP.  \n");
112
 
        NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOPCAST);
113
 
 
114
 
 
115
 
}
116
 
 
117
 
static void ndpi_search_sopcast_udp(struct ndpi_detection_module_struct
118
 
                                                                          *ndpi_struct, struct ndpi_flow_struct *flow)
119
 
{
120
 
        struct ndpi_packet_struct *packet = &flow->packet;
121
 
        
122
 
 
123
 
//      struct ndpi_id_struct         *src=ndpi_struct->src;
124
 
//      struct ndpi_id_struct         *dst=ndpi_struct->dst;
125
 
 
126
 
        NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "search sopcast.  \n");
127
 
 
128
 
 
129
 
        if (packet->payload_packet_len == 52 && packet->payload[0] == 0xff
130
 
                && packet->payload[1] == 0xff && packet->payload[2] == 0x01
131
 
                && packet->payload[8] == 0x02 && packet->payload[9] == 0xff
132
 
                && packet->payload[10] == 0x00 && packet->payload[11] == 0x2c
133
 
                && packet->payload[12] == 0x00 && packet->payload[13] == 0x00 && packet->payload[14] == 0x00) {
134
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if I.  \n");
135
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
136
 
                return;
137
 
        }
138
 
        if ((packet->payload_packet_len == 80 || packet->payload_packet_len == 28 || packet->payload_packet_len == 94)
139
 
                && packet->payload[0] == 0x00 && (packet->payload[2] == 0x02 || packet->payload[2] == 0x01)
140
 
                && packet->payload[8] == 0x01 && packet->payload[9] == 0xff
141
 
                && packet->payload[10] == 0x00 && packet->payload[11] == 0x14
142
 
                && packet->payload[12] == 0x00 && packet->payload[13] == 0x00) {
143
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if II.  \n");
144
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
145
 
                return;
146
 
        }
147
 
        /* this case has been seen once. Please revome this comment, if you see it another time */
148
 
        if (packet->payload_packet_len == 60 && packet->payload[0] == 0x00
149
 
                && packet->payload[2] == 0x01
150
 
                && packet->payload[8] == 0x03 && packet->payload[9] == 0xff
151
 
                && packet->payload[10] == 0x00 && packet->payload[11] == 0x34
152
 
                && packet->payload[12] == 0x00 && packet->payload[13] == 0x00 && packet->payload[14] == 0x00) {
153
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if III.  \n");
154
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
155
 
                return;
156
 
        }
157
 
        if (packet->payload_packet_len == 42 && packet->payload[0] == 0x00
158
 
                && packet->payload[1] == 0x02 && packet->payload[2] == 0x01
159
 
                && packet->payload[3] == 0x07 && packet->payload[4] == 0x03
160
 
                && packet->payload[8] == 0x06
161
 
                && packet->payload[9] == 0x01 && packet->payload[10] == 0x00
162
 
                && packet->payload[11] == 0x22 && packet->payload[12] == 0x00 && packet->payload[13] == 0x00) {
163
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if IV.  \n");
164
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
165
 
                return;
166
 
        }
167
 
        if (packet->payload_packet_len == 28 && packet->payload[0] == 0x00
168
 
                && packet->payload[1] == 0x0c && packet->payload[2] == 0x01
169
 
                && packet->payload[3] == 0x07 && packet->payload[4] == 0x00
170
 
                && packet->payload[8] == 0x01
171
 
                && packet->payload[9] == 0x01 && packet->payload[10] == 0x00
172
 
                && packet->payload[11] == 0x14 && packet->payload[12] == 0x00 && packet->payload[13] == 0x00) {
173
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if V.  \n");
174
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
175
 
                return;
176
 
        }
177
 
        /* this case has been seen once. Please revome this comment, if you see it another time */
178
 
        if (packet->payload_packet_len == 286 && packet->payload[0] == 0x00
179
 
                && packet->payload[1] == 0x02 && packet->payload[2] == 0x01
180
 
                && packet->payload[3] == 0x07 && packet->payload[4] == 0x03
181
 
                && packet->payload[8] == 0x06
182
 
                && packet->payload[9] == 0x01 && packet->payload[10] == 0x01
183
 
                && packet->payload[11] == 0x16 && packet->payload[12] == 0x00 && packet->payload[13] == 0x00) {
184
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if VI.  \n");
185
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
186
 
                return;
187
 
        }
188
 
        if (packet->payload_packet_len == 76 && packet->payload[0] == 0xff
189
 
                && packet->payload[1] == 0xff && packet->payload[2] == 0x01
190
 
                && packet->payload[8] == 0x0c && packet->payload[9] == 0xff
191
 
                && packet->payload[10] == 0x00 && packet->payload[11] == 0x44
192
 
                && packet->payload[16] == 0x01 && packet->payload[15] == 0x01
193
 
                && packet->payload[12] == 0x00 && packet->payload[13] == 0x00 && packet->payload[14] == 0x00) {
194
 
                NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "found sopcast with if VII.  \n");
195
 
                ndpi_int_sopcast_add_connection(ndpi_struct, flow);
196
 
                return;
197
 
        }
198
 
 
199
 
        /* Attention please: no asymmetric detection necessary. This detection works asymmetrically as well. */
200
 
 
201
 
        NDPI_LOG(NDPI_PROTOCOL_SOPCAST, ndpi_struct, NDPI_LOG_DEBUG, "exclude sopcast.  \n");
202
 
        NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOPCAST);
203
 
 
204
 
 
205
 
 
206
 
}
207
 
 
208
 
void ndpi_search_sopcast(struct ndpi_detection_module_struct
209
 
                                                   *ndpi_struct, struct ndpi_flow_struct *flow)
210
 
{
211
 
        struct ndpi_packet_struct *packet = &flow->packet;
212
 
 
213
 
        if (packet->udp != NULL)
214
 
                ndpi_search_sopcast_udp(ndpi_struct, flow);
215
 
        if (packet->tcp != NULL)
216
 
                ndpi_search_sopcast_tcp(ndpi_struct, flow);
217
 
 
218
 
}
219
 
#endif