trema 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. data/.gitignore +1 -1
  2. data/Doxyfile +1 -1
  3. data/Gemfile +18 -6
  4. data/README.md +112 -5
  5. data/Rakefile +3 -1
  6. data/Rantfile +88 -1
  7. data/bin/trema +248 -0
  8. data/bin/trema-config +59 -0
  9. data/cruise.rb +1 -1
  10. data/features/example.dumper.feature +45 -65
  11. data/features/example.hello_trema.feature +21 -0
  12. data/features/example.learning_switch.feature +26 -28
  13. data/features/example.list_switches.feature +19 -33
  14. data/features/example.message.echo_reply.feature +10 -10
  15. data/features/example.message.echo_request.feature +2 -2
  16. data/features/example.message.features_request.feature +6 -5
  17. data/features/example.message.hello.feature +47 -13
  18. data/features/example.message.set_config.feature +4 -4
  19. data/features/example.message.vendor-action.feature +23 -0
  20. data/features/example.multi_learning_switch.feature +14 -42
  21. data/features/example.packet_in.feature +31 -0
  22. data/features/example.packetin_filter_config.feature +11 -7
  23. data/features/example.patch_panel.feature +29 -0
  24. data/features/example.repeater_hub.feature +43 -40
  25. data/features/example.switch_info.feature +51 -0
  26. data/features/example.switch_monitor.feature +24 -42
  27. data/features/packetin_filter.feature +28 -22
  28. data/features/step_definitions/misc_steps.rb +19 -8
  29. data/features/step_definitions/send_packets_steps.rb +1 -10
  30. data/features/step_definitions/stats_steps.rb +4 -4
  31. data/features/support/env.rb +2 -1
  32. data/features/support/hooks.rb +35 -2
  33. data/features/switch_manager.feature +18 -12
  34. data/features/trema-config.feature +26 -39
  35. data/features/trema.dump_flows.feature +26 -12
  36. data/features/trema.help.feature +26 -0
  37. data/features/trema.kill.feature +39 -41
  38. data/features/trema.killall.feature +23 -23
  39. data/features/trema.reset_stats.feature +50 -10
  40. data/features/trema.run.feature +28 -39
  41. data/features/trema.send_packets.feature +29 -40
  42. data/features/trema.show_stats.feature +30 -33
  43. data/features/trema.up.feature +33 -0
  44. data/features/trema.version.feature +9 -0
  45. data/ruby/extconf.rb +7 -0
  46. data/ruby/trema/aggregate-stats-reply.rb +3 -3
  47. data/ruby/trema/app.rb +5 -1
  48. data/ruby/trema/barrier-request.c +55 -30
  49. data/ruby/trema/cli.rb +8 -8
  50. data/ruby/trema/command.rb +1 -3
  51. data/ruby/trema/command/dump_flows.rb +5 -24
  52. data/ruby/trema/command/kill.rb +31 -36
  53. data/ruby/trema/command/killall.rb +1 -19
  54. data/{features/step_definitions/kill_steps.rb → ruby/trema/command/netns.rb} +13 -5
  55. data/ruby/trema/command/reset_stats.rb +3 -23
  56. data/ruby/trema/command/ruby.rb +2 -19
  57. data/ruby/trema/command/run.rb +6 -27
  58. data/ruby/trema/command/send_packets.rb +6 -90
  59. data/ruby/trema/command/show_stats.rb +21 -40
  60. data/ruby/trema/command/up.rb +5 -26
  61. data/ruby/trema/command/version.rb +1 -5
  62. data/ruby/trema/controller.c +14 -16
  63. data/ruby/trema/custom-switch.rb +56 -0
  64. data/ruby/trema/desc-stats-reply.rb +5 -5
  65. data/ruby/trema/dsl/configuration.rb +4 -0
  66. data/{features/step_definitions/up_steps.rb → ruby/trema/dsl/custom-switch.rb} +18 -4
  67. data/ruby/trema/dsl/netns.rb +78 -0
  68. data/ruby/trema/dsl/parser.rb +2 -0
  69. data/ruby/trema/dsl/runner.rb +8 -0
  70. data/ruby/trema/dsl/syntax.rb +18 -0
  71. data/ruby/trema/echo-reply.h +2 -2
  72. data/ruby/trema/echo-request.c +3 -5
  73. data/ruby/trema/enqueue.rb +2 -2
  74. data/ruby/trema/error.c +3 -3
  75. data/ruby/trema/executables.rb +26 -2
  76. data/ruby/trema/features-request.c +3 -5
  77. data/ruby/trema/flow-removed.c +6 -6
  78. data/ruby/trema/flow-stats-reply.rb +6 -8
  79. data/ruby/trema/flow.rb +12 -1
  80. data/ruby/trema/get-config-request.c +55 -28
  81. data/ruby/trema/hello.c +3 -5
  82. data/ruby/trema/host.rb +8 -0
  83. data/ruby/trema/list-switches-reply.c +1 -1
  84. data/ruby/trema/mac.rb +1 -1
  85. data/ruby/trema/match.c +15 -14
  86. data/ruby/trema/monkey-patch/module/deprecation.rb +0 -2
  87. data/ruby/trema/netns.rb +127 -0
  88. data/ruby/trema/ordered-hash.rb +5 -4
  89. data/ruby/trema/packet-in.c +136 -113
  90. data/ruby/trema/packet-queue.rb +9 -9
  91. data/ruby/trema/packetin-filter.rb +1 -1
  92. data/ruby/trema/phost.rb +16 -7
  93. data/ruby/trema/port-mod.c +6 -5
  94. data/ruby/trema/port-stats-reply.rb +2 -2
  95. data/ruby/trema/process.rb +29 -0
  96. data/ruby/trema/queue-stats-reply.rb +2 -4
  97. data/ruby/trema/send-out-port.rb +5 -3
  98. data/ruby/trema/set-eth-addr.rb +4 -0
  99. data/ruby/trema/set-ip-addr.rb +4 -2
  100. data/ruby/trema/set-ip-dst-addr.rb +2 -1
  101. data/ruby/trema/set-ip-src-addr.rb +2 -1
  102. data/ruby/trema/set-ip-tos.rb +3 -2
  103. data/ruby/trema/set-transport-port.rb +3 -2
  104. data/ruby/trema/set-vlan-priority.rb +3 -2
  105. data/ruby/trema/set-vlan-vid.rb +5 -4
  106. data/ruby/trema/shell/reset_stats.rb +2 -1
  107. data/ruby/trema/shell/run.rb +1 -1
  108. data/ruby/trema/shell/send_packets.rb +1 -1
  109. data/ruby/trema/shell/show_stats.rb +1 -1
  110. data/ruby/trema/stats-helper.rb +3 -3
  111. data/ruby/trema/stats-reply.c +26 -17
  112. data/ruby/trema/stats-request.c +39 -41
  113. data/ruby/trema/switch-daemon.rb +36 -31
  114. data/ruby/trema/switch.c +1 -1
  115. data/ruby/trema/table-stats-reply.rb +1 -1
  116. data/ruby/trema/timers.rb +13 -13
  117. data/ruby/trema/trema.c +3 -3
  118. data/ruby/trema/tremashark.rb +9 -2
  119. data/ruby/trema/util.rb +39 -15
  120. data/ruby/trema/vendor-action.rb +8 -3
  121. data/ruby/trema/vendor-stats-reply.rb +4 -6
  122. data/ruby/trema/vendor.c +1 -1
  123. data/ruby/trema/version.rb +1 -1
  124. data/spec/trema/barrier-request_spec.rb +47 -37
  125. data/spec/trema/controller_spec.rb +1 -0
  126. data/spec/trema/dsl/runner_spec.rb +8 -3
  127. data/spec/trema/dsl/vhost_spec.rb +8 -8
  128. data/spec/trema/echo-request_spec.rb +1 -0
  129. data/spec/trema/features-request_spec.rb +1 -0
  130. data/spec/trema/flow-removed_spec.rb +9 -9
  131. data/spec/trema/get-config-request_spec.rb +51 -39
  132. data/spec/trema/match_spec.rb +1 -1
  133. data/spec/trema/openflow-error_spec.rb +11 -11
  134. data/spec/trema/packet-out_spec.rb +5 -5
  135. data/spec/trema/queue-get-config-reply_spec.rb +1 -1
  136. data/spec/trema/queue-get-config-request_spec.rb +1 -1
  137. data/spec/trema/set-eth-dst-addr_spec.rb +1 -1
  138. data/spec/trema/set-eth-src-addr_spec.rb +1 -1
  139. data/spec/trema/set-ip-dst-addr_spec.rb +1 -0
  140. data/spec/trema/set-ip-src-addr_spec.rb +1 -0
  141. data/spec/trema/set-ip-tos_spec.rb +1 -0
  142. data/spec/trema/set-transport-dst-port_spec.rb +1 -0
  143. data/spec/trema/set-transport-src-port_spec.rb +1 -0
  144. data/spec/trema/set-vlan-priority_spec.rb +1 -0
  145. data/spec/trema/set-vlan-vid_spec.rb +2 -1
  146. data/spec/trema/stats-reply_spec.rb +38 -36
  147. data/spec/trema/stats-request_spec.rb +6 -6
  148. data/spec/trema/strip-vlan-header_spec.rb +1 -0
  149. data/spec/trema/util_spec.rb +3 -2
  150. data/spec/trema/vendor-action_spec.rb +9 -8
  151. data/src/examples/dumper/dumper.c +8 -6
  152. data/src/examples/dumper/dumper.rb +1 -1
  153. data/{features/step_definitions/killall_steps.rb → src/examples/hello_trema/hello-trema.rb} +6 -5
  154. data/src/examples/hello_trema/hello_trema.c +4 -4
  155. data/src/examples/learning_switch/learning_switch.c +1 -1
  156. data/src/examples/list_switches/list_switches.c +2 -2
  157. data/src/examples/match_compare/match-compare.rb +2 -2
  158. data/src/examples/multi_learning_switch/multi-learning-switch.rb +1 -1
  159. data/src/examples/multi_learning_switch/multi_learning_switch.c +3 -3
  160. data/src/examples/openflow_message/README +1 -1
  161. data/src/examples/openflow_message/echo-request.rb +1 -1
  162. data/src/examples/openflow_message/features_request.c +21 -21
  163. data/src/examples/openflow_message/hello.c +1 -3
  164. data/src/examples/openflow_message/hello.rb +9 -24
  165. data/src/examples/{hello_trema/hello_trema.rb → openflow_message/vendor-action.rb} +17 -7
  166. data/src/examples/openflow_message/vendor_action.c +105 -0
  167. data/src/examples/openflow_switch/hello_switch.c +81 -0
  168. data/src/examples/packet_in/packet-in.rb +9 -13
  169. data/src/examples/packetin_filter_config/packetin_filter_config.c +2 -2
  170. data/src/examples/patch_panel/network.conf +14 -0
  171. data/src/examples/patch_panel/patch-panel.conf +1 -0
  172. data/{features/step_definitions/show_stats_steps.rb → src/examples/patch_panel/patch-panel.rb} +29 -13
  173. data/src/examples/switch_info/{switch_info.rb → switch-info.rb} +2 -2
  174. data/src/examples/switch_info/switch_info.c +4 -4
  175. data/src/examples/switch_monitor/switch_monitor.c +3 -3
  176. data/src/examples/traffic_monitor/counter.c +9 -9
  177. data/src/examples/traffic_monitor/fdb.c +9 -9
  178. data/src/lib/arp.h +1 -1
  179. data/src/lib/buffer.c +4 -3
  180. data/src/lib/byteorder.c +31 -5
  181. data/src/lib/byteorder.h +2 -2
  182. data/src/lib/chibach.c +8 -6
  183. data/src/lib/daemon.c +29 -3
  184. data/src/lib/doubly_linked_list.c +6 -1
  185. data/src/lib/ether.c +1 -1
  186. data/src/lib/ether.h +1 -1
  187. data/src/lib/event_handler.c +3 -3
  188. data/src/lib/hash_table.c +1 -1
  189. data/src/lib/linked_list.c +50 -2
  190. data/src/lib/linked_list.h +2 -2
  191. data/src/lib/log.c +122 -22
  192. data/src/lib/log.h +13 -9
  193. data/src/lib/management_interface.c +361 -0
  194. data/src/lib/management_interface.h +42 -0
  195. data/src/lib/management_service_interface.c +104 -0
  196. data/src/lib/management_service_interface.h +136 -0
  197. data/src/lib/match_table.c +5 -5
  198. data/src/lib/message_queue.c +5 -3
  199. data/src/lib/message_queue.h +1 -1
  200. data/src/lib/messenger.c +73 -39
  201. data/src/lib/messenger.h +3 -2
  202. data/src/lib/openflow_application_interface.c +17 -17
  203. data/src/lib/openflow_message.c +175 -23
  204. data/src/lib/openflow_message.h +2 -1
  205. data/src/lib/openflow_switch_interface.c +12 -12
  206. data/src/lib/packet_parser.c +11 -32
  207. data/src/lib/packetin_filter_interface.c +5 -5
  208. data/src/lib/persistent_storage.c +7 -7
  209. data/src/lib/secure_channel.c +6 -6
  210. data/src/lib/secure_channel.h +1 -1
  211. data/src/lib/stat.c +54 -17
  212. data/src/lib/stat.h +9 -0
  213. data/src/lib/timer.c +11 -10
  214. data/src/lib/trema.c +38 -9
  215. data/src/lib/trema.h +1 -0
  216. data/src/lib/trema_private.h +6 -0
  217. data/src/lib/trema_wrapper.c +4 -4
  218. data/src/lib/trema_wrapper.h +10 -10
  219. data/src/lib/utility.c +6 -6
  220. data/src/management/application.c +224 -0
  221. data/src/management/echo.c +185 -0
  222. data/src/management/set_logging_level.c +153 -0
  223. data/src/management/show_stats.c +150 -0
  224. data/src/management/trema_manager +184 -0
  225. data/src/packetin_filter/packetin_filter.c +31 -29
  226. data/src/switch_manager/cookie_table.c +7 -7
  227. data/src/switch_manager/dpid_table.c +3 -3
  228. data/src/switch_manager/dpid_table.h +0 -1
  229. data/src/switch_manager/management_interface.h +0 -1
  230. data/src/switch_manager/ofpmsg_recv.c +3 -3
  231. data/src/switch_manager/ofpmsg_recv.h +0 -1
  232. data/src/switch_manager/ofpmsg_send.c +2 -2
  233. data/src/switch_manager/ofpmsg_send.h +0 -1
  234. data/src/switch_manager/secure_channel_listener.c +2 -2
  235. data/src/switch_manager/secure_channel_receiver.c +2 -2
  236. data/src/switch_manager/secure_channel_receiver.h +0 -1
  237. data/src/switch_manager/secure_channel_sender.c +8 -1
  238. data/src/switch_manager/service_interface.c +5 -4
  239. data/src/switch_manager/switch.c +79 -53
  240. data/src/switch_manager/switch_manager.c +24 -22
  241. data/src/switch_manager/xid_table.c +6 -6
  242. data/src/switch_manager/xid_table.h +0 -1
  243. data/src/tremashark/README +4 -3
  244. data/src/tremashark/packet_capture.c +11 -9
  245. data/src/tremashark/pcap_queue.c +2 -2
  246. data/src/tremashark/pcap_queue.h +2 -2
  247. data/src/tremashark/plugin/packet-trema/Makefile +1 -1
  248. data/src/tremashark/plugin/packet-trema/Makefile.common +1 -1
  249. data/src/tremashark/plugin/packet-trema/packet-trema.c +50 -37
  250. data/src/tremashark/queue.c +5 -4
  251. data/src/tremashark/queue.h +1 -1
  252. data/src/tremashark/stdin_relay.c +10 -8
  253. data/src/tremashark/syslog_relay.c +14 -12
  254. data/src/tremashark/tremashark.c +15 -18
  255. data/trema +2 -96
  256. data/trema-config +2 -52
  257. data/trema.gemspec +12 -1
  258. data/unittests/cmockery_trema.h +14 -13
  259. data/unittests/lib/buffer_test.c +1 -1
  260. data/unittests/lib/byteorder_test.c +108 -25
  261. data/unittests/lib/daemon_test.c +141 -5
  262. data/unittests/lib/doubly_linked_list_test.c +5 -1
  263. data/unittests/lib/ether_test.c +4 -4
  264. data/unittests/lib/hash_table_test.c +5 -3
  265. data/unittests/lib/linked_list_test.c +82 -4
  266. data/unittests/lib/log_test.c +96 -5
  267. data/unittests/lib/management_interface_test.c +240 -0
  268. data/unittests/lib/management_service_interface_test.c +319 -0
  269. data/unittests/lib/message_queue_test.c +6 -2
  270. data/unittests/lib/messenger_test.c +167 -2
  271. data/unittests/lib/openflow_application_interface_test.c +16 -22
  272. data/unittests/lib/openflow_message_test.c +721 -24
  273. data/unittests/lib/packet_info_test.c +2 -2
  274. data/unittests/lib/packet_parser_test.c +15 -16
  275. data/unittests/lib/packetin_filter_interface_test.c +6 -6
  276. data/unittests/lib/persistent_storage_test.c +11 -11
  277. data/unittests/lib/stat_test.c +151 -7
  278. data/unittests/lib/timer_test.c +1 -1
  279. data/unittests/lib/trema_private_test.c +2 -2
  280. data/unittests/lib/trema_test.c +40 -12
  281. data/unittests/lib/utility_test.c +3 -3
  282. data/unittests/lib/wrapper_test.c +3 -3
  283. data/unittests/packetin_filter/packetin_filter_test.c +12 -11
  284. data/unittests/switch_manager/switch_manager_test.c +29 -22
  285. metadata +99 -20
  286. data/features/step_definitions/log_steps.rb +0 -90
  287. data/features/step_definitions/run_steps.rb +0 -91
  288. data/features/trema.feature +0 -27
  289. data/features/tutorial.hello_trema.feature +0 -27
  290. data/features/tutorial.packet_in.feature +0 -47
  291. data/features/tutorial.switch_info.feature +0 -55
  292. data/ruby/trema/command/usage.rb +0 -63
@@ -53,4 +53,3 @@ void dump_xid_table( void );
53
53
  * indent-tabs-mode: nil
54
54
  * End:
55
55
  */
56
-
@@ -26,9 +26,10 @@ Pre-requirements
26
26
  ----------------
27
27
 
28
28
  You need to download the source code of wireshark before you start to build
29
- tremashark. We have tested with wireshark 1.4.4. Note that the package
30
- "wireshark-dev" included in Ubuntu or Debian will not work for building the
31
- wireshark plugin. You can get the source code from the following site:
29
+ tremashark. We have tested with wireshark 1.6.10 and 1.8.2. Note that the
30
+ package "wireshark-dev" included in Ubuntu or Debian will not work for
31
+ building the wireshark plugin. You can get the source code from the following
32
+ site:
32
33
 
33
34
  http://www.wireshark.org/download.html
34
35
 
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * packet_capture: An application that captures packets from a network interface
3
- *
3
+ *
4
4
  * Author: Yasunobu Chiba
5
5
  *
6
6
  * Copyright (C) 2008-2012 NEC Corporation
@@ -179,7 +179,7 @@ flush_packet_buffer( void *user_data ) {
179
179
  debug( "Flushing packet queue ( length = %u ).", packet_queue->length );
180
180
 
181
181
  buffer *packet = peek( packet_queue );
182
- while( packet != NULL ) {
182
+ while ( packet != NULL ) {
183
183
  bool ret = send_message( dump_service_name, MESSENGER_DUMP_PCAP, packet->data, packet->length );
184
184
  if ( ret ) {
185
185
  packet = dequeue( packet_queue );
@@ -214,12 +214,14 @@ usage( void ) {
214
214
  printf(
215
215
  "Usage: packet_capture -i NETWORK_INTERFACE [OPTION]...\n"
216
216
  "\n"
217
- " -i NETWORK_INTERFACE network interface for packet capturing\n"
218
- " -s DUMP_SERVICE_NAME dump service name\n"
219
- " -n, --name=SERVICE_NAME service name\n"
220
- " -d, --daemonize run in the background\n"
221
- " -l, --logging_level=LEVEL set logging level\n"
222
- " -h, --help display this help and exit\n"
217
+ " -i NETWORK_INTERFACE network interface for packet capturing\n"
218
+ " -s DUMP_SERVICE_NAME dump service name\n"
219
+ " -n, --name=SERVICE_NAME service name\n"
220
+ " -d, --daemonize run in the background\n"
221
+ " -l, --logging_level=LEVEL set logging level\n"
222
+ " -g, --syslog output log messages to syslog\n"
223
+ " -f, --logging_facility=FACILITY set syslog facility\n"
224
+ " -h, --help display this help and exit\n"
223
225
  );
224
226
  }
225
227
 
@@ -235,7 +237,7 @@ static void
235
237
  parse_options( int *argc, char **argv[] ) {
236
238
  int opt;
237
239
 
238
- while( 1 ) {
240
+ while ( 1 ) {
239
241
  opt = getopt( *argc, *argv, "i:s:" );
240
242
 
241
243
  if ( opt < 0 ) {
@@ -57,7 +57,7 @@ delete_pcap_queue( void ) {
57
57
 
58
58
 
59
59
  buffer *
60
- create_pcap_packet( void* pcap_header, size_t pcap_len, void* dump_header, size_t dump_len, void* data, size_t data_len ) {
60
+ create_pcap_packet( void *pcap_header, size_t pcap_len, void *dump_header, size_t dump_len, void *data, size_t data_len ) {
61
61
  size_t length = pcap_len + dump_len + data_len;
62
62
  assert( length != 0 );
63
63
  assert( pcap_header != NULL && dump_header != NULL );
@@ -90,7 +90,7 @@ create_pcap_packet( void* pcap_header, size_t pcap_len, void* dump_header, size_
90
90
  bool
91
91
  delete_pcap_packet( buffer *packet ) {
92
92
  assert( packet != NULL );
93
-
93
+
94
94
  free_buffer( packet );
95
95
 
96
96
  return true;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Queue implementation for keeping pcap formatted packets.
3
- *
3
+ *
4
4
  * Author: Yasunori Nakazawa, Yasunobu Chiba
5
5
  *
6
6
  * Copyright (C) 2008-2012 NEC Corporation
@@ -36,7 +36,7 @@ typedef enum {
36
36
 
37
37
  bool create_pcap_queue( void );
38
38
  bool delete_pcap_queue( void );
39
- buffer* create_pcap_packet( void* pcap_header, size_t pcap_len, void* dump_header, size_t dump_len, void* data, size_t data_len );
39
+ buffer *create_pcap_packet( void *pcap_header, size_t pcap_len, void *dump_header, size_t dump_len, void *data, size_t data_len );
40
40
  bool delete_pcap_packet( buffer *packet );
41
41
  queue_status enqueue_pcap_packet( buffer *packet );
42
42
  queue_status peek_pcap_packet( buffer **packet );
@@ -40,7 +40,7 @@ ifeq ($(OSTYPE),SunOS)
40
40
  ENDIAN=-D_BIG_ENDIAN_
41
41
  endif
42
42
 
43
- INC_GLIB = -I/usr/include/glib-2.0 -I/usr/local/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/i386-linux-gnu/glib-2.0/include
43
+ INC_GLIB = -I/usr/include/glib-2.0 -I/usr/local/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
44
44
  INC_OPENFLOW = -I../../../../objects/openflow
45
45
  INC_TREMA = -I../../../lib
46
46
 
@@ -28,4 +28,4 @@ DISSECTOR_INCLUDES =
28
28
  # Dissector helpers. They're included in the source files in this
29
29
  # directory, but they're not dissectors themselves, i.e. they're not
30
30
  # used to generate "register.c").
31
- DISSECTOR_SUPPORT_SRC =
31
+ DISSECTOR_SUPPORT_SRC =
@@ -22,20 +22,20 @@
22
22
  #include "config.h"
23
23
  #endif
24
24
 
25
- #include <stdio.h>
26
- #include <stdlib.h>
27
- #include <glib.h>
25
+ #include <arpa/inet.h>
26
+ #include <epan/addr_resolv.h>
27
+ #include <epan/dissectors/packet-tcp.h>
28
28
  #include <epan/emem.h>
29
+ #include <epan/etypes.h>
30
+ #include <epan/ipproto.h>
29
31
  #include <epan/packet.h>
30
- #include <epan/dissectors/packet-tcp.h>
31
32
  #include <epan/prefs.h>
32
- #include <epan/ipproto.h>
33
- #include <epan/etypes.h>
34
- #include <epan/addr_resolv.h>
35
33
  #include <epan/reassemble.h>
34
+ #include <glib.h>
36
35
  #include <pcap/pcap.h>
36
+ #include <stdio.h>
37
+ #include <stdlib.h>
37
38
  #include <string.h>
38
- #include <arpa/inet.h>
39
39
  #include "messenger.h"
40
40
  #include "openflow_service_interface.h"
41
41
 
@@ -47,7 +47,6 @@
47
47
 
48
48
  #define UDP_PORT_SYSLOG 514
49
49
 
50
-
51
50
  // Macro for debug use
52
51
  //#define PRINTF( ... ) printf( __VA_ARGS__ )
53
52
  #define PRINTF( ... )
@@ -69,7 +68,7 @@ typedef struct message_pcap_dump_header {
69
68
  uint16_t app_name_len;
70
69
  uint16_t service_name_len;
71
70
  uint32_t data_len;
72
- } __attribute__( ( packed ) ) message_pcap_dump_header;
71
+ } __attribute__( ( packed ) ) message_pcap_dump_header;
73
72
 
74
73
  typedef struct stream_id {
75
74
  gchar *app_name;
@@ -180,6 +179,9 @@ static int hf_trema_fragment_overlap_conflict = -1;
180
179
  static int hf_trema_fragment_multiple_tails = -1;
181
180
  static int hf_trema_fragment_too_long_fragment = -1;
182
181
  static int hf_trema_fragment_error = -1;
182
+ #ifndef WIRESHARK_VERSION_OLDER_THAN_160
183
+ static int hf_trema_fragment_count = -1;
184
+ #endif
183
185
 
184
186
  // Reassembled in field
185
187
  static int hf_trema_reassembled_in = -1;
@@ -250,6 +252,9 @@ static const fragment_items trema_fragment_items = {
250
252
  &hf_trema_fragment_multiple_tails,
251
253
  &hf_trema_fragment_too_long_fragment,
252
254
  &hf_trema_fragment_error,
255
+ #ifndef WIRESHARK_VERSION_OLDER_THAN_160
256
+ &hf_trema_fragment_count,
257
+ #endif
253
258
  // Reassembled in field
254
259
  &hf_trema_reassembled_in,
255
260
  // Reassembled length field
@@ -268,7 +273,7 @@ check_packet_status( guint32 packet_number ) {
268
273
  if ( packet_number == 0 || packet_number > packets_status_size ) {
269
274
  return FALSE;
270
275
  }
271
-
276
+
272
277
  if ( packets_status[ packet_number - 1 ] ) {
273
278
  return TRUE;
274
279
  }
@@ -283,7 +288,7 @@ check_packet_status( guint32 packet_number ) {
283
288
  static void
284
289
  update_packet_status( guint32 packet_number, guint32 reassemble_id ) {
285
290
  const guint32 PACKET_STATUS_CHUNK_SIZE = 1000;
286
-
291
+
287
292
  guint32 current_size = packets_status_size;
288
293
  packet_status_info *p = NULL;
289
294
 
@@ -297,7 +302,7 @@ update_packet_status( guint32 packet_number, guint32 reassemble_id ) {
297
302
  packet_status_info **new_table_buffer = g_malloc( packets_status_size * sizeof( packet_status_info * ) );
298
303
  memset( new_table_buffer, 0, packets_status_size * sizeof( packet_status_info * ) );
299
304
  if ( packets_status != NULL ) {
300
- memcpy( ( void * )new_table_buffer, ( void * )packets_status, current_size * sizeof( packet_status_info * ) );
305
+ memcpy( ( void * ) new_table_buffer, ( void * ) packets_status, current_size * sizeof( packet_status_info * ) );
301
306
  g_free( packets_status );
302
307
  }
303
308
  packets_status = new_table_buffer;
@@ -317,7 +322,7 @@ update_packet_status( guint32 packet_number, guint32 reassemble_id ) {
317
322
  static packet_status_info *
318
323
  get_packet_status( guint32 packet_number ) {
319
324
  packet_status_info *p = NULL;
320
-
325
+
321
326
  if ( check_packet_status( packet_number ) ) {
322
327
  p = packets_status[ packet_number - 1 ];
323
328
  }
@@ -332,7 +337,7 @@ static void
332
337
  clear_packet_status() {
333
338
  if ( packets_status != NULL ) {
334
339
  guint count;
335
-
340
+
336
341
  for ( count = 0; count < packets_status_size; count++ ) {
337
342
  if ( packets_status[ count ] ) {
338
343
  g_free( packets_status[ count ] );
@@ -391,7 +396,7 @@ generate_reassemble_id() {
391
396
  * FALSE means the stream has enough fragments, it can be reassembled.
392
397
  */
393
398
  static gboolean
394
- is_last_fragment( fragmented_stream_info* fragment_info ) {
399
+ is_last_fragment( fragmented_stream_info *fragment_info ) {
395
400
  assert( fragment_info != NULL );
396
401
 
397
402
  if ( fragment_info->unreceived_length <= 0 ) {
@@ -470,11 +475,11 @@ add_fragmented_stream_info( tvbuff_t *tvb, gint offset, stream_id *stream_name )
470
475
  guint32 received_message_length = tvb_length_remaining( tvb, offset );
471
476
  fragment_info = g_malloc( sizeof( fragmented_stream_info ) );
472
477
  fragment_info->stream_name.app_name = g_malloc( stream_name->app_name_length );
473
- memset( fragment_info->stream_name.app_name, ( int )NULL, stream_name->app_name_length );
478
+ memset( fragment_info->stream_name.app_name, 0, stream_name->app_name_length );
474
479
  strncpy( fragment_info->stream_name.app_name, stream_name->app_name, stream_name->app_name_length - 1 );
475
480
  fragment_info->stream_name.app_name_length = stream_name->app_name_length;
476
481
  fragment_info->stream_name.service_name = g_malloc( stream_name->service_name_length );
477
- memset( fragment_info->stream_name.service_name, ( int )NULL, stream_name->service_name_length );
482
+ memset( fragment_info->stream_name.service_name, 0, stream_name->service_name_length );
478
483
  strncpy( fragment_info->stream_name.service_name, stream_name->service_name, stream_name->service_name_length - 1 );
479
484
  fragment_info->stream_name.service_name_length = stream_name->service_name_length;
480
485
  if ( received_message_length < sizeof( message_header ) ) {
@@ -489,7 +494,7 @@ add_fragmented_stream_info( tvbuff_t *tvb, gint offset, stream_id *stream_name )
489
494
  fragment_info->message_length = tvb_get_ntohl( tvb, offset + offsetof( message_header, message_length ) );
490
495
  fragment_info->temporary_length = FALSE;
491
496
  }
492
-
497
+
493
498
  fragment_info->unreceived_length = fragment_info->message_length - received_message_length;
494
499
  fragment_info->reassemble_id = generate_reassemble_id();
495
500
  fragment_info->number = 0;
@@ -577,7 +582,7 @@ delete_fragmented_stream_info( fragmented_stream_info *fragment_info ) {
577
582
  static gboolean
578
583
  remove_fragmented_stream_info( fragmented_stream_info *fragment_info ) {
579
584
  GList *element;
580
-
585
+
581
586
  assert( fragment_info != NULL );
582
587
 
583
588
  PRINTF( " ** remove_fragmented_stream_info reassemble_id %d\n", fragment_info->reassemble_id );
@@ -590,7 +595,7 @@ remove_fragmented_stream_info( fragmented_stream_info *fragment_info ) {
590
595
  return FALSE;
591
596
  }
592
597
  delete_fragmented_stream_info( element->data );
593
-
598
+
594
599
  return TRUE;
595
600
  }
596
601
 
@@ -645,7 +650,7 @@ reassemble_message( tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_tree *
645
650
 
646
651
  pinfo->fragmented = TRUE;
647
652
  fragment_message = fragment_add_seq_next( tvb, offset, pinfo, packet_status->reassemble_id,
648
- trema_fragment_table, trema_reassembled_table,
653
+ trema_fragment_table, trema_reassembled_table,
649
654
  tvb_length_remaining( tvb, offset ), more_fragment );
650
655
 
651
656
  new_tvb = process_reassembled_data( tvb, offset, pinfo, "Reassembled Trema",
@@ -686,7 +691,7 @@ get_reassembled_message( tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_t
686
691
 
687
692
  packet_status = get_packet_status( pinfo->fd->num );
688
693
  assert( packet_status != NULL );
689
-
694
+
690
695
  more_fragment = FALSE;
691
696
  fragment_info = get_fragmented_stream_info( stream_name );
692
697
  if ( fragment_info != NULL ) {
@@ -699,7 +704,7 @@ get_reassembled_message( tvbuff_t *tvb, gint offset, packet_info *pinfo, proto_t
699
704
  pinfo->fd->flags.visited = 1;
700
705
  save_fragmented = pinfo->fragmented;
701
706
  pinfo->fragmented = TRUE;
702
-
707
+
703
708
  fragment_message = fragment_add_seq_next( tvb, offset, pinfo, packet_status->reassemble_id,
704
709
  trema_fragment_table, trema_reassembled_table,
705
710
  tvb_length_remaining( tvb, offset ), more_fragment );
@@ -792,7 +797,7 @@ dissect_message_pcap_dump_header( tvbuff_t *tvb, packet_info *pinfo, proto_tree
792
797
  uint16_t app_name_len;
793
798
  uint16_t service_name_len;
794
799
  uint32_t data_len;
795
- } __attribute__( ( packed ) ) message_pcap_dump_header;
800
+ } __attribute__( ( packed ) ) message_pcap_dump_header;
796
801
  */
797
802
 
798
803
  gchar *src, *dst;
@@ -825,7 +830,7 @@ dissect_message_pcap_dump_header( tvbuff_t *tvb, packet_info *pinfo, proto_tree
825
830
  case MESSENGER_DUMP_SEND_OVERFLOW:
826
831
  case MESSENGER_DUMP_SEND_CLOSED:
827
832
  {
828
- if ( g_strcasecmp( src, dst ) == 0 ) {
833
+ if ( g_ascii_strcasecmp( src, dst ) == 0 ) {
829
834
  col_add_fstr( pinfo->cinfo, COL_INFO, "%s (%s)",
830
835
  src, names_dump_type[ *dump_type ].strptr );
831
836
  }
@@ -918,7 +923,7 @@ dissect_openflow_service_header( tvbuff_t *tvb, gint offset, proto_tree *trema_t
918
923
  }
919
924
  }
920
925
 
921
- return ( offset - head );
926
+ return ( offset - head );
922
927
  }
923
928
 
924
929
 
@@ -929,7 +934,7 @@ dissect_openflow( tvbuff_t *tvb, packet_info *pinfo, proto_tree *trema_tree ) {
929
934
  col_append_str( pinfo->cinfo, COL_PROTOCOL, "+" );
930
935
  }
931
936
 
932
- if( check_col( pinfo->cinfo, COL_INFO ) ) {
937
+ if ( check_col( pinfo->cinfo, COL_INFO ) ) {
933
938
  col_append_str( pinfo->cinfo, COL_INFO, " => " );
934
939
  }
935
940
 
@@ -969,7 +974,7 @@ dissect_context_handle( tvbuff_t *tvb, gint offset, proto_tree *trema_tree ) {
969
974
  }
970
975
  }
971
976
 
972
- return ( offset - head );
977
+ return ( offset - head );
973
978
  }
974
979
 
975
980
 
@@ -1083,12 +1088,12 @@ dissect_trema_ipc( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tr
1083
1088
 
1084
1089
  if ( visited ) {
1085
1090
  packet_status_info *packet_status = NULL;
1086
-
1091
+
1087
1092
  PRINTF( " Known packet\n" );
1088
1093
  // We have seen this packet
1089
1094
  packet_status = get_packet_status( pinfo->fd->num );
1090
1095
  assert( packet_status != NULL );
1091
-
1096
+
1092
1097
  if ( packet_status->reassemble_id != 0 ) {
1093
1098
  // This is a part of fragment.
1094
1099
  messages_tvb = get_reassembled_message( tvb, offset, pinfo, tree, stream_name );
@@ -1166,7 +1171,7 @@ dissect_trema_ipc( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tr
1166
1171
  }
1167
1172
  else {
1168
1173
  guint32 message_length = tvb_get_ntohl( messages_tvb, offset + offsetof( message_header, message_length ) );
1169
-
1174
+
1170
1175
  if ( remaining_length < message_length ) {
1171
1176
  // new fragment
1172
1177
  dissect_message_dump( messages_tvb, offset, trema_tree );
@@ -1259,7 +1264,7 @@ dissect_ethernet( tvbuff_t *tvb, packet_info *pinfo, proto_tree *trema_tree ) {
1259
1264
  col_append_str( pinfo->cinfo, COL_PROTOCOL, "+" );
1260
1265
  }
1261
1266
 
1262
- if( check_col( pinfo->cinfo, COL_INFO ) ) {
1267
+ if ( check_col( pinfo->cinfo, COL_INFO ) ) {
1263
1268
  col_append_str( pinfo->cinfo, COL_INFO, " => " );
1264
1269
  }
1265
1270
 
@@ -1330,14 +1335,17 @@ dissect_syslog( tvbuff_t *tvb, packet_info *pinfo, proto_tree *trema_tree ) {
1330
1335
  col_append_str( pinfo->cinfo, COL_PROTOCOL, "+" );
1331
1336
  }
1332
1337
 
1333
- if( check_col( pinfo->cinfo, COL_INFO ) ) {
1338
+ if ( check_col( pinfo->cinfo, COL_INFO ) ) {
1334
1339
  col_append_str( pinfo->cinfo, COL_INFO, " => " );
1335
1340
  }
1336
1341
 
1337
1342
  col_set_fence( pinfo->cinfo, COL_PROTOCOL );
1338
1343
  col_set_fence( pinfo->cinfo, COL_INFO );
1339
-
1344
+ #ifndef WIRESHARK_VERSION_OLDER_THAN_160
1345
+ dissector_try_uint( udp_dissector_table, UDP_PORT_SYSLOG, tvb, pinfo, trema_tree );
1346
+ #else
1340
1347
  dissector_try_port( udp_dissector_table, UDP_PORT_SYSLOG, tvb, pinfo, trema_tree );
1348
+ #endif
1341
1349
  }
1342
1350
  else {
1343
1351
  gint length = tvb_length_remaining( tvb, 0 );
@@ -1406,7 +1414,7 @@ dissect_text_dump( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tr
1406
1414
  col_append_str( pinfo->cinfo, COL_PROTOCOL, "+TEXT" );
1407
1415
  }
1408
1416
 
1409
- if( check_col( pinfo->cinfo, COL_INFO ) && string != NULL ) {
1417
+ if ( check_col( pinfo->cinfo, COL_INFO ) && string != NULL ) {
1410
1418
  col_append_str( pinfo->cinfo, COL_INFO, " => " );
1411
1419
  col_append_str( pinfo->cinfo, COL_INFO, string );
1412
1420
  }
@@ -1427,7 +1435,7 @@ dissect_trema( tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ) {
1427
1435
  stream_id stream_name;
1428
1436
 
1429
1437
  PRINTF( "----- start %u\n", pinfo->fd->num );
1430
-
1438
+
1431
1439
  if ( tree == NULL ) { // FIXME: is it okay to return here?
1432
1440
  PRINTF( "----- end %u (tree is NULL)\n", pinfo->fd->num );
1433
1441
  return;
@@ -1610,6 +1618,11 @@ proto_register_trema() {
1610
1618
  { &hf_trema_fragment_error,
1611
1619
  { "Trema defragmentation error", "trema.fragment.error",
1612
1620
  FT_FRAMENUM, BASE_NONE, NO_STRINGS, NO_MASK, NULL, HFILL }},
1621
+ #ifndef WIRESHARK_VERSION_OLDER_THAN_160
1622
+ { &hf_trema_fragment_count,
1623
+ { "Trema defragmentation count", "trema.fragment.count",
1624
+ FT_UINT32, BASE_DEC, NO_STRINGS, NO_MASK, NULL, HFILL }},
1625
+ #endif
1613
1626
  { &hf_trema_reassembled_in,
1614
1627
  { "Reassembled in", "trema.reassembled.in",
1615
1628
  FT_FRAMENUM, BASE_NONE, NO_STRINGS, NO_MASK, NULL, HFILL }},
@@ -39,7 +39,7 @@ bool
39
39
  delete_queue( queue *queue ) {
40
40
  assert( queue != NULL );
41
41
 
42
- while( queue->head != NULL ) {
42
+ while ( queue->head != NULL ) {
43
43
  queue_element *e = queue->head;
44
44
  if ( queue->head->data != NULL ) {
45
45
  free_buffer( queue->head->data );
@@ -75,7 +75,7 @@ enqueue( queue *queue, buffer *data ) {
75
75
 
76
76
  queue->tail->next = new_tail;
77
77
  queue->tail = new_tail;
78
- queue->length++;
78
+ __sync_add_and_fetch( &queue->length, 1 ); // this must be an atomic operation for thread safety
79
79
 
80
80
  collect_garbage( queue );
81
81
 
@@ -92,7 +92,7 @@ dequeue( queue *queue ) {
92
92
  buffer *data = next->data;
93
93
  next->data = NULL; // data must be freed by caller
94
94
  queue->divider = next;
95
- queue->length--;
95
+ __sync_sub_and_fetch( &queue->length, 1 ); // this must be an atomic operation for thread safety
96
96
 
97
97
  return data;
98
98
  }
@@ -139,7 +139,8 @@ sort_queue( queue *queue, bool compare( const buffer *x, const buffer *y ) ) {
139
139
  do {
140
140
  elements[ j ]->data = elements[ j - 1 ]->data;
141
141
  j--;
142
- } while ( j > 0 && compare( elements[ j - 1 ]->data, data ) );
142
+ }
143
+ while ( j > 0 && compare( elements[ j - 1 ]->data, data ) );
143
144
  elements[ j ]->data = data;
144
145
  }
145
146
  }