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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
|
/* packet-jxta.c
*
* Routines for JXTA packet dissection
* JXTA specification from https://jxta-spec.dev.java.net (now at https://github.com/chaupal/jxta-spec ?)
*
* Copyright 2004-08, Mike Duigou <bondolo@dev.java.net>
*
* Heavily based on packet-jabber.c, which in turn is heavily based on
* on packet-acap.c, which in turn is heavily based on
* packet-imap.c, Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
* Copied from packet-pop.c, packet-jabber.c, packet-udp.c, packet-http.c
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 2000 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#define WS_LOG_DOMAIN "jxta"
#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/conversation_table.h>
#include <epan/prefs.h>
#include <epan/to_str.h>
#include <epan/address_types.h>
#include <epan/expert.h>
#include <wsutil/str_util.h>
#include "packet-jxta.h"
#include "packet-media-type.h"
void proto_register_jxta(void);
void proto_reg_handoff_jxta(void);
static const char JXTA_UDP_SIG[] = { 'J', 'X', 'T', 'A' };
static const char JXTA_MSG_SIG[] = { 'j', 'x', 'm', 'g' };
static const char JXTA_MSGELEM_SIG[] = { 'j', 'x', 'e', 'l' };
static const char JXTA_WELCOME_MSG_SIG[] = { 'J', 'X', 'T', 'A', 'H', 'E', 'L', 'L', 'O', ' ' };
static const char* JXTA_WELCOME_MSG_VERSION_1_1 = "1.1";
static const char* JXTA_WELCOME_MSG_VERSION_3_0 = "3.0";
static const int JXTA_MSG_VERSION_1;
static const int JXTA_MSG_VERSION_2 = 1;
static const int JXTAMSG1_ELMFLAG_TYPE = 1 << 0;
static const int JXTAMSG1_ELMFLAG_ENCODING = 1 << 1;
static const int JXTAMSG1_ELMFLAG_SIGNATURE = 1 << 2;
static const int JXTAMSG2_ELMFLAG_UINT64_LENS = 1 << 0;
static const int JXTAMSG2_ELMFLAG_NAME_LITERAL = 1 << 1;
static const int JXTAMSG2_ELMFLAG_TYPE = 1 << 2;
static const int JXTAMSG2_ELMFLAG_SIGNATURE = 1 << 3;
static const int JXTAMSG2_ELMFLAG_ENCODINGS = 1 << 4;
static int proto_jxta;
static int proto_message_jxta;
static int jxta_tap;
static dissector_table_t media_type_dissector_table;
static dissector_handle_t media_handle;
static dissector_handle_t stream_jxta_handle;
static dissector_handle_t tls_handle;
static int hf_uri_addr;
static int hf_uri_src;
static int hf_uri_dst;
static int hf_jxta_udp;
static int hf_jxta_udpsig;
static int hf_jxta_welcome;
static int hf_jxta_welcome_initiator;
static int hf_jxta_welcome_sig;
static int hf_jxta_welcome_destAddr;
static int hf_jxta_welcome_pubAddr;
static int hf_jxta_welcome_peerid;
static int hf_jxta_welcome_noProp;
static int hf_jxta_welcome_msgVers;
static int hf_jxta_welcome_variable;
static int hf_jxta_welcome_version;
static int hf_jxta_framing;
static int hf_jxta_framing_header;
static int hf_jxta_framing_header_name;
static int hf_jxta_framing_header_value_length;
static int hf_jxta_framing_header_value;
static int hf_jxta_message_address;
static int hf_jxta_message_src;
static int hf_jxta_message_dst;
static int hf_jxta_message_sig;
static int hf_jxta_message_version;
static int hf_jxta_message_flags;
static int hf_jxta_message_flag_utf16be;
static int hf_jxta_message_flag_ucs32be;
static int hf_jxta_message_names_count;
static int hf_jxta_message_names_name;
static int hf_jxta_message_element_count;
static int hf_jxta_element;
static int hf_jxta_element_sig;
static int hf_jxta_element1_namespaceid;
static int hf_jxta_element2_namespaceid;
static int hf_jxta_element2_nameid;
static int hf_jxta_element2_mimeid;
static int hf_jxta_element2_encodingid;
static int hf_jxta_element_flags;
static int hf_jxta_element1_flag_hasType;
static int hf_jxta_element1_flag_hasEncoding;
static int hf_jxta_element1_flag_hasSignature;
static int hf_jxta_element2_flag_64bitlens;
static int hf_jxta_element2_flag_nameLiteral;
static int hf_jxta_element2_flag_hasType;
static int hf_jxta_element2_flag_hasSignature;
static int hf_jxta_element2_flag_hasEncoding;
static int hf_jxta_element2_flag_sigOfEncoded;
static int hf_jxta_element_name;
static int hf_jxta_element_type;
static int hf_jxta_element_encoding;
static int hf_jxta_element_content_len;
static int hf_jxta_element_content_len64;
/* static int hf_jxta_element_content; */
/**
* JXTA Protocol subtree handles
**/
static int ett_jxta;
static int ett_jxta_welcome;
static int ett_jxta_udp;
static int ett_jxta_framing;
static int ett_jxta_framing_header;
static int ett_jxta_msg;
static int ett_jxta_msg_flags;
static int ett_jxta_elem;
static int ett_jxta_elem_1_flags;
static int ett_jxta_elem_2_flags;
static expert_field ei_media_too_short;
static int uri_address_type = -1;
/**
* global preferences
**/
static bool gDESEGMENT = true;
static bool gMSG_MEDIA = true;
static dissector_handle_t jxta_udp_handle;
/**
* Stream Conversation data
**/
struct jxta_stream_conversation_data {
port_type tpt_ptype;
address initiator_tpt_address;
uint32_t initiator_tpt_port;
uint32_t initiator_welcome_frame;
address initiator_address;
address receiver_tpt_address;
uint32_t receiver_tpt_port;
uint32_t receiver_welcome_frame;
address receiver_address;
};
typedef struct jxta_stream_conversation_data jxta_stream_conversation_data;
static const char* jxta_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter)
{
if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == uri_address_type))
return "jxta.message.src";
if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == uri_address_type))
return "jxta.message.dst";
if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == uri_address_type))
return "jxta.message.address";
return CONV_FILTER_INVALID;
}
static ct_dissector_info_t jxta_ct_dissector_info = {&jxta_conv_get_filter_type};
static tap_packet_status
jxta_conversation_packet(void *pct, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *vip, tap_flags_t flags)
{
conv_hash_t *hash = (conv_hash_t*) pct;
hash->flags = flags;
const jxta_tap_header *jxtahdr = (const jxta_tap_header *) vip;
add_conversation_table_data(hash, &jxtahdr->src_address, &jxtahdr->dest_address,
0, 0, 1, jxtahdr->size, NULL, NULL, &jxta_ct_dissector_info, CONVERSATION_NONE);
return TAP_PACKET_REDRAW;
}
static const char* jxta_endpoint_get_filter_type(endpoint_item_t* endpoint, conv_filter_type_e filter)
{
if ((filter == CONV_FT_ANY_ADDRESS) && (endpoint->myaddress.type == uri_address_type))
return "jxta.message.address";
return CONV_FILTER_INVALID;
}
static et_dissector_info_t jxta_endpoint_dissector_info = {&jxta_endpoint_get_filter_type};
static tap_packet_status
jxta_endpoint_packet(void *pit, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *vip, tap_flags_t flags)
{
conv_hash_t *hash = (conv_hash_t*) pit;
hash->flags = flags;
const jxta_tap_header *jxtahdr = (const jxta_tap_header *)vip;
/* Take two "add" passes per packet, adding for each direction, ensures that all
packets are counted properly (even if address is sending to itself)
XXX - this could probably be done more efficiently inside endpoint_table */
add_endpoint_table_data(hash, &jxtahdr->src_address, 0, true, 1, jxtahdr->size, &jxta_endpoint_dissector_info, ENDPOINT_NONE);
add_endpoint_table_data(hash, &jxtahdr->dest_address, 0, false, 1, jxtahdr->size, &jxta_endpoint_dissector_info, ENDPOINT_NONE);
return TAP_PACKET_REDRAW;
}
static int uri_to_str(const address* addr, char *buf, int buf_len)
{
int copy_len = addr->len < (buf_len - 1) ? addr->len : (buf_len - 1);
memcpy(buf, addr->data, copy_len );
buf[copy_len] = '\0';
return copy_len+1;
}
static int uri_str_len(const address* addr)
{
return addr->len+1;
}
static const char* uri_col_filter_str(const address* addr _U_, bool is_src)
{
if (is_src)
return "uri.src";
return "uri.dst";
}
/**
* Prototypes
**/
static int dissect_jxta_udp(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data);
static int dissect_jxta_stream(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data);
static jxta_stream_conversation_data *get_tpt_conversation(packet_info * pinfo);
static conversation_t *get_peer_conversation(packet_info * pinfo, jxta_stream_conversation_data* tpt_conv_data, bool create);
static int dissect_jxta_welcome(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, address * found_addr, bool initiator);
static int dissect_jxta_message_framing(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, uint64_t * content_length,
char ** content_type);
static int dissect_jxta_message(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data);
static int dissect_jxta_message_element_1(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, unsigned ns_count,
const char ** namespaces);
static int dissect_jxta_message_element_2(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, unsigned ns_count,
const char ** namespaces);
static int dissect_media( const char* fullmediatype, tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree);
/**
* Heuristically dissect a tvbuff containing a JXTA UDP Message
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return true if the tvb contained JXTA data which was dissected otherwise false
**/
static bool dissect_jxta_UDP_heur(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
{
/* This is a heuristic dissector, which means we get all the UDP
* traffic not sent to a known dissector and not claimed by
* a heuristic dissector called before us!
*/
int save_desegment_offset;
uint32_t save_desegment_len;
int ret;
if (tvb_strneql(tvb, 0, JXTA_UDP_SIG, sizeof (JXTA_UDP_SIG)) != 0) {
/* Not a JXTA UDP packet (or not enough bytes to check for the sig) */
return false;
}
save_desegment_offset = pinfo->desegment_offset;
save_desegment_len = pinfo->desegment_len;
ret = dissect_jxta_udp(tvb, pinfo, tree, NULL);
/* ws_message( "%d Heuristic UDP Dissection : %d", pinfo->num, ret ); */
if (ret < 0) {
/*
* UDP is not a packet stream protocol, so the UDP dissector
* should not, and will not, do the sort of dissection help
* that the TCP dissector will. If JXTA messages don't
* start and end on UDP packet boundaries, the JXTA dissector
* will have to do its own byte stream reassembly.
*/
pinfo->desegment_offset = save_desegment_offset;
pinfo->desegment_len = save_desegment_len;
return false;
} else if (ret == 0) {
/*
* A clear rejection.
*/
pinfo->desegment_offset = save_desegment_offset;
pinfo->desegment_len = save_desegment_len;
return false;
} else {
/*
* A clear acceptance.
*/
return true;
}
}
/**
* Heuristically dissect a tvbuff containing a JXTA TCP Stream
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return true if the tvb contained JXTA data which was dissected otherwise false
**/
static bool dissect_jxta_TCP_heur(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
{
/* This is a heuristic dissector, which means we get all the TCP
* traffic not sent to a known dissector and not claimed by
* a heuristic dissector called before us!
*/
int save_desegment_offset;
uint32_t save_desegment_len;
int ret;
save_desegment_offset = pinfo->desegment_offset;
save_desegment_len = pinfo->desegment_len;
ret = dissect_jxta_stream(tvb, pinfo, tree, NULL);
/* ws_message( "%d Heuristic TCP Dissection : %d", pinfo->num, ret ); */
if (ret < 0) {
/*
* A heuristic dissector for a TCP-based protocol can reject
* a packet, or it can request that more data be provided.
* It must not attempt to do both, as the notion of doing both
* is nonsensical - if the packet isn't considered a packet
* for the dissector's protocol, that dissector won't be
* dissecting it no matter *how* much more data is added.
*
* Therefore, we treat a negative return from
* dissect_jxta_stream() as a rejection.
*
* If that's not desired - i.e., if we should keep trying to get
* more data, in the hopes that we'll eventually be able to
* determine whether the packet is a JXTA packet or not - we
* should, in this case, leave pinfo->desegment_offset and
* pinfo->desegment_len alone, and return true, *NOT* false.
*/
pinfo->desegment_offset = save_desegment_offset;
pinfo->desegment_len = save_desegment_len;
return false;
} else if (ret == 0) {
/*
* A clear rejection.
*/
pinfo->desegment_offset = save_desegment_offset;
pinfo->desegment_len = save_desegment_len;
return false;
} else {
/*
* A clear acceptance.
*/
return true;
}
}
/**
* Heuristically dissect a tvbuff containing a JXTA SCTP Stream
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return true if the tvb contained JXTA data which was dissected otherwise false
**/
static bool dissect_jxta_SCTP_heur(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
{
/* This is a heuristic dissector, which means we get all the SCTP
* traffic not sent to a known dissector and not claimed by
* a heuristic dissector called before us!
*/
int save_desegment_offset;
uint32_t save_desegment_len;
int ret;
save_desegment_offset = pinfo->desegment_offset;
save_desegment_len = pinfo->desegment_len;
ret = dissect_jxta_stream(tvb, pinfo, tree, NULL);
/* ws_message( "%d Heuristic SCTP Dissection : %d", pinfo->num, ret ); */
if (ret < 0) {
/*
* SCTP is not a byte stream protocol, so the SCTP dissector
* should not, and will not, do the sort of dissection help
* that the SCTP dissector will. If JXTA messages don't
* start and end on SCTP packet boundaries, the JXTA dissector
* will have to do its own byte stream reassembly.
*
* The SCTP dissector currently won't do reassembly. If that
* causes a problem for the JXTA dissector, the correct fix
* is to implement reassembly in the SCTP dissector, so *all*
* dissectors for protocols running atop SCTP can benefit from
* it.
*/
pinfo->desegment_offset = save_desegment_offset;
pinfo->desegment_len = save_desegment_len;
return false;
} else if (ret == 0) {
/*
* A clear rejection.
*/
pinfo->desegment_offset = save_desegment_offset;
pinfo->desegment_len = save_desegment_len;
return false;
} else {
/*
* A clear acceptance.
*/
return true;
}
}
/**
* Dissect a tvbuff containing a JXTA UDP header, JXTA Message framing and a JXTA Message
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
static int dissect_jxta_udp(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
{
unsigned offset = 0;
unsigned available;
int needed = 0;
conversation_t *conversation = find_or_create_conversation(pinfo);
conversation_set_dissector(conversation, jxta_udp_handle);
while (true) {
tvbuff_t *jxta_message_framing_tvb;
int processed = 0;
uint64_t content_length = -1;
char *content_type = NULL;
available = tvb_reported_length_remaining(tvb, offset);
if (available < sizeof(JXTA_UDP_SIG)) {
needed = (int) (sizeof(JXTA_UDP_SIG) - available);
break;
}
if (tvb_memeql(tvb, offset, (const uint8_t*)JXTA_UDP_SIG, sizeof(JXTA_UDP_SIG)) != 0) {
/* not ours */
return 0;
}
offset += (int)sizeof(JXTA_UDP_SIG);
jxta_message_framing_tvb = tvb_new_subset_remaining(tvb, offset);
processed = dissect_jxta_message_framing(jxta_message_framing_tvb, pinfo, NULL, &content_length, &content_type);
if ((0 == processed) || (NULL == content_type) || (content_length <= 0) || (content_length > UINT_MAX)) {
/** Buffer did not begin with valid framing headers */
return 0;
}
if (processed < 0) {
needed = -processed;
break;
}
offset += processed;
available = tvb_reported_length_remaining(tvb, offset);
if (available < content_length) {
needed = (int) (content_length - available);
break;
}
offset += (unsigned) content_length;
break;
}
if ((needed > 0) && gDESEGMENT && pinfo->can_desegment) {
/* ws_message( "UDP requesting %d more bytes", needed ); */
pinfo->desegment_offset = 0;
pinfo->desegment_len = needed;
return -needed;
}
col_set_str(pinfo->cinfo, COL_PROTOCOL, "JXTA");
unsigned tree_offset = 0;
proto_item *jxta_tree_item =
proto_tree_add_protocol_format(tree, proto_jxta, tvb, tree_offset, -1, "JXTA" );
proto_tree *jxta_tree = proto_item_add_subtree(jxta_tree_item, ett_jxta);
proto_item *jxta_udp_tree_item =
proto_tree_add_none_format(jxta_tree, hf_jxta_udp, tvb, tree_offset, -1, "JXTA UDP Message");
proto_tree *jxta_udp_tree = proto_item_add_subtree(jxta_udp_tree_item, ett_jxta_udp);
tvbuff_t *jxta_message_framing_tvb;
uint64_t content_length = -1;
char *content_type = NULL;
tvbuff_t *jxta_message_tvb;
proto_tree_add_item(jxta_udp_tree, hf_jxta_udpsig, tvb, tree_offset, (int)sizeof(JXTA_UDP_SIG), ENC_ASCII);
tree_offset += (int)sizeof(JXTA_UDP_SIG);
jxta_message_framing_tvb = tvb_new_subset_remaining(tvb, tree_offset);
tree_offset += dissect_jxta_message_framing(jxta_message_framing_tvb, pinfo, jxta_tree, &content_length, &content_type);
jxta_message_tvb = tvb_new_subset_length(tvb, tree_offset, (int) content_length);
tree_offset += dissect_media(content_type, jxta_message_tvb, pinfo, tree);
proto_item_set_end(jxta_udp_tree_item, tvb, tree_offset);
// offset is based on reported lengths. tree_offset is based on captured lengths via dissect_media.
// Comment this out for now in favor of dissect_media's expert warning.
// DISSECTOR_ASSERT(tree_offset == offset);
return offset;
}
/**
* Dissect a tvbuff containing JXTA stream PDUs. This commonly includes
* connections over TCP sockets.
*
* <p/>The stream (in both directions) will consist of a JXTA Welcome Message
* followed by an indeterminate number of JXTA Message Framing Headers and
* JXTA Messages.
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
static int dissect_jxta_stream(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
{
unsigned offset = 0;
unsigned available = tvb_reported_length_remaining(tvb, offset);
int processed = 0;
int needed = 0;
jxta_stream_conversation_data *tpt_conv_data = NULL;
proto_item *jxta_tree_item = NULL;
proto_tree *jxta_tree = NULL;
/* ws_message("Dissecting%s : %d", (NULL != tree) ? " for display" : "", pinfo->num ); */
if (available < sizeof(JXTA_WELCOME_MSG_SIG)) {
needed = (int) (sizeof(JXTA_WELCOME_MSG_SIG) - available);
goto Common_Exit;
}
if (0 == tvb_memeql(tvb, 0, (const uint8_t*)JXTA_WELCOME_MSG_SIG, sizeof(JXTA_WELCOME_MSG_SIG))) {
/* The beginning of a JXTA stream connection */
address *welcome_addr;
bool initiator = false;
tpt_conv_data = get_tpt_conversation(pinfo);
if (0 == tpt_conv_data->initiator_welcome_frame) {
/* The initiator welcome frame */
tpt_conv_data->tpt_ptype = pinfo->ptype;
tpt_conv_data->initiator_welcome_frame = pinfo->num;
copy_address_wmem(wmem_file_scope(), &tpt_conv_data->initiator_tpt_address, &pinfo->src);
tpt_conv_data->initiator_tpt_port = pinfo->srcport;
welcome_addr = &tpt_conv_data->initiator_address;
initiator = true;
} else {
if (tpt_conv_data->initiator_welcome_frame >= pinfo->num) {
/* what we saw previously was the receiver welcome message */
tpt_conv_data->receiver_welcome_frame = tpt_conv_data->initiator_welcome_frame;
tpt_conv_data->receiver_tpt_address = tpt_conv_data->initiator_tpt_address;
tpt_conv_data->receiver_tpt_port = tpt_conv_data->initiator_tpt_port;
tpt_conv_data->receiver_address = tpt_conv_data->initiator_address;
tpt_conv_data->initiator_welcome_frame = pinfo->num;
copy_address_wmem(wmem_file_scope(), &tpt_conv_data->initiator_tpt_address, &pinfo->src);
tpt_conv_data->initiator_tpt_port = pinfo->srcport;
welcome_addr = &tpt_conv_data->initiator_address;
initiator = true;
} else {
/* The receiver welcome frame */
tpt_conv_data->tpt_ptype = pinfo->ptype;
tpt_conv_data->receiver_welcome_frame = pinfo->num;
copy_address_wmem(wmem_file_scope(), &tpt_conv_data->receiver_tpt_address, &pinfo->src);
tpt_conv_data->receiver_tpt_port = pinfo->srcport;
welcome_addr = &tpt_conv_data->receiver_address;
initiator = false;
}
}
processed = dissect_jxta_welcome(tvb, pinfo, NULL, welcome_addr, initiator);
if( processed < 0 ) {
needed = -processed;
goto Common_Exit;
}
/* redo, this time creating the display tree. */
jxta_tree_item = proto_tree_add_protocol_format(tree, proto_jxta, tvb, offset, -1, "JXTA" );
jxta_tree = proto_item_add_subtree(jxta_tree_item, ett_jxta);
processed = dissect_jxta_welcome(tvb, pinfo, jxta_tree, welcome_addr, initiator);
} else {
/* Somewhere in the middle of a JXTA stream connection */
int64_t content_length = INT64_C(-1);
char *content_type = NULL;
int headers_len = dissect_jxta_message_framing(tvb, pinfo, NULL, (uint64_t*) &content_length, &content_type);
if ((0 == headers_len) || (NULL == content_type) || (content_length <= 0) || (content_length > UINT_MAX)) {
/** Buffer did not begin with valid framing headers */
return 0;
}
/* ws_message("%d Tpt %s:%d -> %s:%d tvb len=%d\n\t%s %d", pinfo->num,
address_to_str(pinfo->pool, &pinfo->src), pinfo->srcport,
address_to_str(pinfo->pool, &pinfo->dst), pinfo->destport,
tvb_reported_length_remaining(tvb, 0),
content_type ? content_type : "[unknown content type]", (int) content_length); */
if (headers_len < 0) {
/* negative headers_len means we need more bytes */
needed = -headers_len;
goto Common_Exit;
}
available = tvb_reported_length_remaining(tvb, offset + headers_len);
if (available >= content_length) {
tvbuff_t *jxta_message_tvb = tvb_new_subset_length(tvb, offset + headers_len, (int) content_length);
conversation_t *peer_conversation = NULL;
jxta_tree_item = proto_tree_add_protocol_format(tree, proto_jxta, tvb, offset, -1, "JXTA" );
jxta_tree = proto_item_add_subtree(jxta_tree_item, ett_jxta);
/* Redo header processing, this time populating the tree. */
headers_len = dissect_jxta_message_framing(tvb, pinfo, jxta_tree, &content_length, &content_type);
tpt_conv_data = get_tpt_conversation(pinfo);
peer_conversation = get_peer_conversation(pinfo, tpt_conv_data, true);
/* Use our source and destination addresses if we have them */
if (NULL != peer_conversation) {
/* ws_message("%d Tpt %s:%d -> %s:%d", pinfo->num,
address_to_str(pinfo->pool, &tpt_conv_data->initiator_tpt_address), tpt_conv_data->initiator_tpt_port,
address_to_str(pinfo->pool, &tpt_conv_data->receiver_tpt_address), tpt_conv_data->receiver_tpt_port); */
if (addresses_equal(&pinfo->src, &tpt_conv_data->initiator_tpt_address)
&& tpt_conv_data->initiator_tpt_port == pinfo->srcport) {
/* ws_message("%d From initiator : %s -> %s ", pinfo->num,
address_to_str(pinfo->pool, &tpt_conv_data->initiator_address),
address_to_str(pinfo->pool, &tpt_conv_data->receiver_address)); */
copy_address_shallow(&pinfo->src, &tpt_conv_data->initiator_address);
pinfo->srcport = 0;
copy_address_shallow(&pinfo->dst, &tpt_conv_data->receiver_address);
pinfo->destport = 0;
pinfo->ptype = PT_NONE;
} else if (addresses_equal(&pinfo->src, &tpt_conv_data->receiver_tpt_address) &&
tpt_conv_data->receiver_tpt_port == pinfo->srcport) {
/* ws_message("%d From receiver : %s -> %s ", pinfo->num,
address_to_str(pinfo->pool, &tpt_conv_data->receiver_address),
address_to_str(pinfo->pool, &tpt_conv_data->initiator_address)); */
copy_address_shallow(&pinfo->src, &tpt_conv_data->receiver_address);
pinfo->srcport = 0;
copy_address_shallow(&pinfo->dst, &tpt_conv_data->initiator_address);
pinfo->destport = 0;
pinfo->ptype = PT_NONE;
} else {
/* ws_message("%d Nothing matches %s:%d -> %s:%d", pinfo->num,
address_to_str(pinfo->pool, &pinfo->src), pinfo->srcport,
address_to_str(pinfo->pool, &pinfo->dst), pinfo->destport); */
}
}
processed = headers_len;
processed += dissect_media(content_type, jxta_message_tvb, pinfo, tree);
} else {
/* we need more bytes before we can process message body. */
needed = (int) ((unsigned) content_length - available);
goto Common_Exit;
}
}
offset += processed;
Common_Exit:
if ((needed > 0) && gDESEGMENT && pinfo->can_desegment) {
/* ws_message( "Stream requesting %d more bytes", needed ); */
pinfo->desegment_offset = offset;
pinfo->desegment_len = needed;
return -needed;
}
return offset;
}
/**
* Find or possibly create a transport conversation object for the connection
* which is associated with the packet info.
*
* @param pinfo The packet info from the underlying transport.
**/
static jxta_stream_conversation_data *get_tpt_conversation(packet_info * pinfo)
{
conversation_t *tpt_conversation = find_or_create_conversation(pinfo);
jxta_stream_conversation_data *tpt_conv_data;
conversation_set_dissector(tpt_conversation, stream_jxta_handle);
tpt_conv_data = (jxta_stream_conversation_data *) conversation_get_proto_data(tpt_conversation, proto_jxta);
if (NULL == tpt_conv_data) {
tpt_conv_data = wmem_new(wmem_file_scope(), jxta_stream_conversation_data);
tpt_conv_data->tpt_ptype = pinfo->ptype;
copy_address_wmem(wmem_file_scope(), &tpt_conv_data->initiator_tpt_address, &pinfo->src);
tpt_conv_data->initiator_tpt_port = pinfo->srcport;
tpt_conv_data->initiator_welcome_frame = 0;
clear_address(&tpt_conv_data->initiator_address);
copy_address_wmem(wmem_file_scope(), &tpt_conv_data->receiver_tpt_address, &pinfo->dst);
tpt_conv_data->receiver_tpt_port = pinfo->destport;
tpt_conv_data->receiver_welcome_frame = 0;
clear_address(&tpt_conv_data->receiver_address);
conversation_add_proto_data(tpt_conversation, proto_jxta, tpt_conv_data);
}
return tpt_conv_data;
}
/**
* Find or possibly create a peer conversation object for the connection
* which is associated with the packet info.
*
* @param tpt_conv_data The transport conversation from which we will locate the peer conversation.
* @param create If true then create a new conversation object if necessary.
**/
static conversation_t *get_peer_conversation(packet_info * pinfo, jxta_stream_conversation_data* tpt_conv_data, bool create)
{
conversation_t * peer_conversation = NULL;
if ((AT_NONE != tpt_conv_data->initiator_address.type) && (AT_NONE != tpt_conv_data->receiver_address.type)) {
peer_conversation = find_conversation(pinfo->num, &tpt_conv_data->initiator_address, &tpt_conv_data->receiver_address,
CONVERSATION_NONE, 0, 0, NO_PORT_B);
if (create && (NULL == peer_conversation)) {
peer_conversation = conversation_new(pinfo->num, &tpt_conv_data->initiator_address,
&tpt_conv_data->receiver_address, CONVERSATION_NONE, 0, 0, NO_PORT2);
conversation_set_dissector(peer_conversation, stream_jxta_handle);
}
}
return peer_conversation;
}
/**
* Dissect a tvbuff containing a JXTA Welcome Message
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @param found_addr The address found in the welcome message.
* @param initiator If true then we believe this welcome message to be the initiator's.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
static int dissect_jxta_welcome(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, address * found_addr, bool initiator)
{
unsigned offset = 0;
int afterwelcome;
int first_linelen;
unsigned available = tvb_reported_length_remaining(tvb, offset);
char **tokens = NULL;
if (available < sizeof(JXTA_WELCOME_MSG_SIG)) {
return (int) (available - sizeof(JXTA_WELCOME_MSG_SIG));
}
if (0 != tvb_memeql(tvb, 0, (const uint8_t*)JXTA_WELCOME_MSG_SIG, sizeof(JXTA_WELCOME_MSG_SIG))) {
/* not ours! */
return 0;
}
first_linelen = tvb_find_line_end(tvb, offset, -1, &afterwelcome, gDESEGMENT && pinfo->can_desegment);
if (-1 == first_linelen) {
if (available > 4096) {
/* it's too far too be reasonable */
return 0;
} else {
/* ask for more bytes */
return -DESEGMENT_ONE_MORE_SEGMENT;
}
}
/* Dissect the Welcome Message */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "JXTA");
col_set_str(pinfo->cinfo, COL_INFO, "Welcome");
{
char *welcomeline = tvb_get_string_enc(pinfo->pool, tvb, offset, first_linelen, ENC_ASCII);
char **current_token;
unsigned token_offset = offset;
proto_item *jxta_welcome_tree_item = NULL;
proto_tree *jxta_welcome_tree = NULL;
tokens = wmem_strsplit(pinfo->pool, welcomeline, " ", 255);
current_token = tokens;
if (tree) {
jxta_welcome_tree_item =
proto_tree_add_none_format(tree, hf_jxta_welcome, tvb, offset, afterwelcome,
"JXTA Connection Welcome Message, %s", welcomeline);
jxta_welcome_tree = proto_item_add_subtree(jxta_welcome_tree_item, ett_jxta_welcome);
}
if (jxta_welcome_tree) {
proto_item *jxta_welcome_initiator_item =
proto_tree_add_boolean(jxta_welcome_tree, hf_jxta_welcome_initiator, tvb, 0, 0, initiator);
proto_item_set_generated(jxta_welcome_initiator_item);
}
if (NULL != *current_token) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_sig, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
} else {
/* invalid welcome message */
afterwelcome = 0;
goto Common_Exit;
}
if (NULL != *current_token) {
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_destAddr, tvb, token_offset, (int) strlen(*current_token),
ENC_ASCII);
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
} else {
/* invalid welcome message */
afterwelcome = 0;
goto Common_Exit;
}
if (NULL != *current_token) {
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_pubAddr, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
} else {
/* invalid welcome message */
afterwelcome = 0;
goto Common_Exit;
}
if (NULL != *current_token) {
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_peerid, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
col_append_str(pinfo->cinfo, COL_INFO, (initiator ? " -> " : " <- ") );
col_append_str(pinfo->cinfo, COL_INFO, *current_token);
if (NULL != found_addr) {
set_address(found_addr, uri_address_type, (int)strlen(*current_token) + 1, wmem_strdup(wmem_file_scope(), *current_token));
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
} else {
/* invalid welcome message */
afterwelcome = 0;
goto Common_Exit;
}
if (NULL != *current_token) {
int variable_tokens = 0;
char **variable_token = current_token;
while(NULL != *variable_token) {
variable_tokens++;
variable_token++;
}
if( variable_tokens < 1 ) {
/* invalid welcome message */
afterwelcome = 0;
goto Common_Exit;
}
if( (2 == variable_tokens) && (0 == strcmp(JXTA_WELCOME_MSG_VERSION_1_1, current_token[variable_tokens -1])) ) {
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_noProp, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_version, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
} else if( (3 == variable_tokens) && (0 == strcmp(JXTA_WELCOME_MSG_VERSION_3_0, current_token[variable_tokens -1])) ) {
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_noProp, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_msgVers, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
if (jxta_welcome_tree) {
proto_tree_add_item(jxta_welcome_tree, hf_jxta_welcome_version, tvb, token_offset, (int) strlen(*current_token), ENC_ASCII);
}
} else {
/* Unrecognized Welcome Version */
int each_variable_token;
for( each_variable_token = 0; each_variable_token < variable_tokens; each_variable_token++ ) {
if (jxta_welcome_tree) {
jxta_welcome_tree_item = proto_tree_add_item(jxta_welcome_tree,
(each_variable_token < (variable_tokens -1) ? hf_jxta_welcome_variable : hf_jxta_welcome_version),
tvb, token_offset, (int) strlen(*current_token), ENC_ASCII|ENC_NA);
proto_item_append_text(jxta_welcome_tree_item, " (UNRECOGNIZED)");
}
token_offset += (unsigned) strlen(*current_token) + 1;
current_token++;
}
}
} else {
/* invalid welcome message */
afterwelcome = 0;
goto Common_Exit;
}
}
Common_Exit:
col_set_writable(pinfo->cinfo, -1, false);
return afterwelcome;
}
/**
* Dissect a tvbuff containing JXTA Message framing.
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @param content_length Pointer to a buffer for storing the value of the
* "content-length" header or NULL.
* @param content_type Pointer-to-a-pointer for a new buffer for storing the
* value of the "content_type-length" header or NULL.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
static int dissect_jxta_message_framing(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, uint64_t * content_length,
char ** content_type)
{
unsigned offset = 0;
unsigned available;
int needed = 0;
/*
* First go around. Make sure all of the bytes are there.
*/
do {
uint8_t headername_len;
uint8_t headername_offset;
uint16_t headervalue_len;
uint16_t headervalue_offset;
available = tvb_reported_length_remaining(tvb, offset);
if (available < 1) {
needed = 1;
break;
} else {
headername_len = tvb_get_uint8(tvb, offset);
offset++;
headername_offset = offset;
available = tvb_reported_length_remaining(tvb, offset);
if (available < headername_len) {
needed = (int) (headername_len - available);
break;
}
if (0 == headername_len) {
break;
}
offset += headername_len;
}
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
} else {
headervalue_len = tvb_get_ntohs(tvb, offset);
offset += 2;
headervalue_offset = offset;
available = tvb_reported_length_remaining(tvb, offset);
if (available < headervalue_len) {
needed = (int) (headervalue_len - available);
break;
}
offset += headervalue_len;
}
if (content_type && (sizeof("content-type") - 1) == headername_len) {
if (0 == tvb_strncaseeql(tvb, headername_offset, "content-type", sizeof("content-type") - 1)) {
*content_type = tvb_get_string_enc(pinfo->pool, tvb, headervalue_offset, headervalue_len, ENC_ASCII);
}
}
if (content_length && (sizeof(uint64_t) == headervalue_len) && ((sizeof("content-length") - 1) == headername_len)) {
if (0 == tvb_strncaseeql(tvb, headername_offset, "content-length", sizeof("content-length") - 1)) {
*content_length = tvb_get_ntoh64(tvb, headervalue_offset);
}
}
} while (true);
if ((needed > 0) && gDESEGMENT && pinfo->can_desegment) {
/* ws_message( "Framing requesting %d more bytes", needed ); */
pinfo->desegment_offset = 0;
pinfo->desegment_len = needed;
return -needed;
}
/*
* Second (optional pass) Now that we are sure that all the bytes are there we update the protocol tree.
*/
if (tree) {
unsigned tree_offset = 0;
proto_item *framing_tree_item;
proto_tree *framing_tree;
framing_tree_item =
proto_tree_add_none_format(tree, hf_jxta_framing, tvb, tree_offset, -1, "JXTA Message Framing Headers");
framing_tree = proto_item_add_subtree(framing_tree_item, ett_jxta_framing);
/* parse framing headers */
do {
uint8_t headernamelen = tvb_get_uint8(tvb, tree_offset);
proto_item *framing_header_tree_item =
proto_tree_add_item(framing_tree, hf_jxta_framing_header, tvb, tree_offset, -1, ENC_NA);
proto_tree *framing_header_tree = proto_item_add_subtree(framing_header_tree_item, ett_jxta_framing_header);
/*
* Put header name into the protocol tree
*/
proto_tree_add_item(framing_header_tree, hf_jxta_framing_header_name, tvb, tree_offset, (int)sizeof(int8_t), ENC_ASCII|ENC_BIG_ENDIAN);
/*
* Append header name into the header protocol item. It's a nice hint so you don't have to reveal all headers.
*/
if (headernamelen > 0) {
proto_item_append_text(framing_header_tree_item, " \"%s\"",
tvb_format_text(pinfo->pool, tvb, tree_offset + 1, headernamelen));
}
tree_offset += 1 + headernamelen;
if (headernamelen > 0) {
uint16_t headervaluelen = tvb_get_ntohs(tvb, tree_offset);
if (tree) {
proto_tree_add_uint(framing_header_tree, hf_jxta_framing_header_value_length, tvb, tree_offset,
2, headervaluelen);
/** TODO bondolo Add specific handling for known header types */
/*
* Put header value into protocol tree.
*/
proto_tree_add_item(framing_header_tree, hf_jxta_framing_header_value, tvb, tree_offset + 2,
headervaluelen, ENC_NA);
}
tree_offset += 2 + headervaluelen;
}
proto_item_set_end(framing_header_tree_item, tvb, tree_offset);
if (0 == headernamelen) {
break;
}
} while (true);
proto_item_set_end(framing_tree_item, tvb, tree_offset);
DISSECTOR_ASSERT(offset == tree_offset);
}
/* return how many bytes we used up. */
return offset;
}
/**
* Dissect a tvbuff containing one or more JXTA Messages.
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
static int dissect_jxta_message(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
{
int complete_messages = 0;
unsigned offset = 0;
unsigned tree_offset = 0;
unsigned available;
int needed = 0;
wmem_strbuf_t* src_addr;
wmem_strbuf_t* dst_addr;
while (true) {
uint8_t message_version;
unsigned message_start_offset = offset;
/* First pass. Make sure all of the bytes we need are available */
available = tvb_reported_length_remaining(tvb, offset);
if((0 == available) && (0 != complete_messages)) {
/* We have discovered all of the complete messages in the tvbuff. */
break;
}
if (available < sizeof(JXTA_MSG_SIG)) {
needed = (int) (sizeof(JXTA_MSG_SIG) - available);
break;
}
if (tvb_memeql(tvb, offset, (const uint8_t*)JXTA_MSG_SIG, sizeof(JXTA_MSG_SIG)) != 0) {
/* It is not one of ours */
return 0;
}
offset += (int)sizeof(JXTA_MSG_SIG);
available = tvb_reported_length_remaining(tvb, offset);
if (available < 1) {
needed = 1;
break;
} else {
message_version = tvb_get_uint8(tvb, offset);
offset++;
if ((JXTA_MSG_VERSION_1 != message_version) && (JXTA_MSG_VERSION_2 != message_version)) {
/* Sort of a lie, we say that we don't recognize it at all. */
return 0;
}
}
/* Read the flags (Version 2 and later) */
if(message_version > 0) {
available = tvb_reported_length_remaining(tvb, offset);
if (available < 1) {
needed = 1;
break;
} else {
offset++;
}
}
/* Read names table */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
} else {
uint16_t msg_names_count = tvb_get_ntohs(tvb, offset);
unsigned each_name;
offset += 2;
for (each_name = 0; each_name < msg_names_count; each_name++) {
uint16_t name_len;
available = tvb_reported_length_remaining(tvb, offset);
if (available < sizeof(name_len)) {
needed = (int) (sizeof(name_len) - available);
break;
}
name_len = tvb_get_ntohs(tvb, offset);
available = tvb_reported_length_remaining(tvb, offset + (int)sizeof(name_len));
if (available < name_len) {
needed = (int) (name_len - available);
break;
}
offset += (int)sizeof(name_len) + name_len;
}
}
/* parse element count */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
} else {
uint16_t elem_count = tvb_get_ntohs(tvb, offset);
unsigned each_elem;
offset += 2;
/* parse elements */
for (each_elem = 0; each_elem < elem_count; each_elem++) {
tvbuff_t *jxta_message_element_tvb = tvb_new_subset_remaining(tvb, offset);
int processed;
if (JXTA_MSG_VERSION_1 == message_version) {
processed = dissect_jxta_message_element_1(jxta_message_element_tvb, pinfo, NULL, 0, NULL);
} else { /* JXTA_MSG_VERSION_2 */
processed = dissect_jxta_message_element_2(jxta_message_element_tvb, pinfo, NULL, 0, NULL);
}
if (processed < 0) {
needed = -processed;
break;
}
if (0 == processed) {
/* XXX bondolo Not really clear what we should do! */
/* eapache: based on reading the code, I believe this can occur
* when the message_version is valid but the JXTA_MSGELEM_SIG
* (some sort of magic number?) is not. This almost
* certainly indicates a corrupt packet, so this should
* probably be expert info, not a ws_warning. Pending confirmation
* just comment it out since a ws_warning is definitely the
* wrong thing to do.
* ws_warning( "Failure processing message element #%d of %d of frame %d", each_elem, elem_count, pinfo->num );
*/
return 0;
}
offset += processed;
}
}
if ((uri_address_type == pinfo->src.type) && (uri_address_type == pinfo->dst.type)) {
jxta_tap_header *tap_header = wmem_new(wmem_file_scope(), jxta_tap_header);
copy_address_shallow(&tap_header->src_address, &pinfo->src);
copy_address_shallow(&tap_header->dest_address, &pinfo->dst);
tap_header->size = offset - message_start_offset ;
tap_queue_packet(jxta_tap, pinfo, tap_header);
}
complete_messages++;
/* ws_message( "%d Scanned message #%d: ", pinfo->num, complete_messages ); */
}
if ((needed > 0) && gDESEGMENT && pinfo->can_desegment) {
/* ws_message("Frame %d: Message requesting %d more bytes", pinfo->num, needed); */
pinfo->desegment_offset = 0;
pinfo->desegment_len = needed;
return -needed;
}
src_addr = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append(src_addr, address_to_str(pinfo->pool, &pinfo->src));
dst_addr = wmem_strbuf_create(pinfo->pool);
wmem_strbuf_append(dst_addr, address_to_str(pinfo->pool, &pinfo->dst));
/* append the port if appropriate */
if (PT_NONE != pinfo->ptype) {
wmem_strbuf_append_printf(src_addr, ":%d", pinfo->srcport);
wmem_strbuf_append_printf(dst_addr, ":%d", pinfo->destport);
}
col_set_str(pinfo->cinfo, COL_PROTOCOL, "JXTA");
if( complete_messages > 1 ) {
col_add_fstr(pinfo->cinfo, COL_INFO, "%d Messages, %s -> %s", complete_messages,
wmem_strbuf_get_str(src_addr), wmem_strbuf_get_str(dst_addr));
} else {
col_add_fstr(pinfo->cinfo, COL_INFO, "Message, %s -> %s",
wmem_strbuf_get_str(src_addr), wmem_strbuf_get_str(dst_addr));
}
col_set_writable(pinfo->cinfo, -1, false);
while( tree && (complete_messages > 0) ) {
proto_item *jxta_msg_tree_item = NULL;
proto_tree *jxta_msg_tree = NULL;
uint8_t message_version;
const char **names_table = NULL;
uint16_t msg_names_count;
unsigned each_name;
uint16_t elem_count;
unsigned each_elem;
proto_item *tree_item;
jxta_msg_tree_item = proto_tree_add_protocol_format(tree, proto_message_jxta, tvb, tree_offset, -1,
"JXTA Message, %s -> %s", wmem_strbuf_get_str(src_addr),
wmem_strbuf_get_str(dst_addr));
jxta_msg_tree = proto_item_add_subtree(jxta_msg_tree_item, ett_jxta_msg);
proto_tree_add_item(jxta_msg_tree, hf_jxta_message_sig, tvb, tree_offset, (int)sizeof(JXTA_MSG_SIG), ENC_ASCII);
tree_offset += (int)sizeof(JXTA_MSG_SIG);
tree_item = proto_tree_add_string(jxta_msg_tree, hf_jxta_message_src, tvb, 0, 0, wmem_strbuf_get_str(src_addr));
proto_item_set_generated(tree_item);
tree_item = proto_tree_add_string(jxta_msg_tree, hf_jxta_message_address, tvb, 0, 0, wmem_strbuf_get_str(src_addr));
proto_item_set_hidden(tree_item);
proto_item_set_generated(tree_item);
if(uri_address_type == pinfo->src.type) {
tree_item = proto_tree_add_string(jxta_msg_tree, hf_uri_src, tvb, 0, 0, wmem_strbuf_get_str(src_addr));
proto_item_set_hidden(tree_item);
proto_item_set_generated(tree_item);
tree_item = proto_tree_add_string(jxta_msg_tree, hf_uri_addr, tvb, 0, 0, wmem_strbuf_get_str(src_addr));
proto_item_set_hidden(tree_item);
proto_item_set_generated(tree_item);
}
tree_item = proto_tree_add_string(jxta_msg_tree, hf_jxta_message_dst, tvb, 0, 0, wmem_strbuf_get_str(dst_addr));
proto_item_set_generated(tree_item);
tree_item = proto_tree_add_string(jxta_msg_tree, hf_jxta_message_address, tvb, 0, 0, wmem_strbuf_get_str(dst_addr));
proto_item_set_hidden(tree_item);
proto_item_set_generated(tree_item);
if(uri_address_type == pinfo->dst.type) {
tree_item = proto_tree_add_string(jxta_msg_tree, hf_uri_dst, tvb, 0, 0, wmem_strbuf_get_str(dst_addr));
proto_item_set_hidden(tree_item);
proto_item_set_generated(tree_item);
tree_item = proto_tree_add_string(jxta_msg_tree, hf_uri_addr, tvb, 0, 0, wmem_strbuf_get_str(dst_addr));
proto_item_set_hidden(tree_item);
proto_item_set_generated(tree_item);
}
message_version = tvb_get_uint8(tvb, tree_offset);
proto_tree_add_uint(jxta_msg_tree, hf_jxta_message_version, tvb, tree_offset, 1, message_version);
tree_offset += 1;
if( message_version > 0 ) {
static int * const flags[] = {
&hf_jxta_message_flag_utf16be,
&hf_jxta_message_flag_ucs32be,
NULL
};
proto_tree_add_bitmask(jxta_msg_tree, tvb, tree_offset, hf_jxta_message_flags, ett_jxta_msg_flags, flags, ENC_NA);
tree_offset += 1;
}
msg_names_count = tvb_get_ntohs(tvb, tree_offset);
proto_tree_add_uint(jxta_msg_tree, hf_jxta_message_names_count, tvb, tree_offset, 2, msg_names_count);
tree_offset += 2;
names_table = (const char **)wmem_alloc(pinfo->pool, (msg_names_count + 2) * sizeof(const char *));
names_table[0] = "";
names_table[1] = "jxta";
/* parse names */
for (each_name = 0; each_name < msg_names_count; each_name++) {
uint16_t name_len = tvb_get_ntohs(tvb, tree_offset);
names_table[2 + each_name] = tvb_get_string_enc(pinfo->pool, tvb, tree_offset + 2, name_len, ENC_ASCII);
proto_tree_add_item(jxta_msg_tree, hf_jxta_message_names_name, tvb, tree_offset, 2, ENC_ASCII|ENC_BIG_ENDIAN);
tree_offset += 2 + name_len;
}
/* parse element count */
elem_count = tvb_get_ntohs(tvb, tree_offset);
proto_tree_add_item(jxta_msg_tree, hf_jxta_message_element_count, tvb, tree_offset, 2, ENC_BIG_ENDIAN);
tree_offset += 2;
/* FIXME bondolo Element count 0 (Process elements until FIN) should be supported. */
/* parse elements */
for (each_elem = 0; each_elem < elem_count; each_elem++) {
tvbuff_t *jxta_message_element_tvb = tvb_new_subset_remaining(tvb, tree_offset);
if(JXTA_MSG_VERSION_1 == message_version) {
tree_offset +=
dissect_jxta_message_element_1(jxta_message_element_tvb, pinfo, jxta_msg_tree, msg_names_count + 2, names_table);
} else if(JXTA_MSG_VERSION_2 == message_version) {
tree_offset +=
dissect_jxta_message_element_2(jxta_message_element_tvb, pinfo, jxta_msg_tree, msg_names_count + 2, names_table);
} else {
/* Sort of a lie, we say that we don't recognize it at all. */
return 0;
}
}
proto_item_set_end(jxta_msg_tree_item, tvb, tree_offset);
complete_messages--;
}
if( tree ) {
/* ws_message( "%d tvb offset : %d tree offset : %d", pinfo->num, offset, tree_offset ); */
DISSECTOR_ASSERT(tree_offset == offset);
}
return offset;
}
/**
* Dissect a tvbuff containing a JXTA Message Element (Version 1).
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
// NOLINTNEXTLINE(misc-no-recursion)
static int dissect_jxta_message_element_1(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, unsigned ns_count,
const char ** names_table)
{
unsigned offset = 0;
unsigned available;
int needed = 0;
uint8_t flags;
/* First pass. Make sure all of the bytes we need are available */
while (true) {
/* signature field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < sizeof(JXTA_MSGELEM_SIG)) {
needed = (int) (sizeof(JXTA_MSGELEM_SIG) - available);
}
if (tvb_memeql(tvb, offset, (const uint8_t*)JXTA_MSGELEM_SIG, sizeof(JXTA_MSGELEM_SIG)) != 0) {
/* It is not one of ours */
return 0;
}
offset += (int)sizeof(JXTA_MSGELEM_SIG);
/* namespace id field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 1) {
needed = 1;
break;
}
offset++;
/* flags field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 1) {
needed = 1;
break;
} else {
flags = tvb_get_uint8(tvb, offset);
offset++;
}
/* name field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
} else {
uint16_t name_len = tvb_get_ntohs(tvb, offset);
offset += 2;
available = tvb_reported_length_remaining(tvb, offset);
if (available < name_len) {
needed = (int) (name_len - available);
break;
}
offset += name_len;
}
/* type field */
if ((flags & JXTAMSG1_ELMFLAG_TYPE) != 0) {
uint16_t type_len;
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
}
type_len = tvb_get_ntohs(tvb, offset);
offset += 2;
available = tvb_reported_length_remaining(tvb, offset);
if (available < type_len) {
needed = (int) (type_len - available);
break;
}
offset += type_len;
}
/* encoding field */
if ((flags & JXTAMSG1_ELMFLAG_ENCODING) != 0) {
uint16_t encoding_len;
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
}
encoding_len = tvb_get_ntohs(tvb, offset);
offset += 2;
available = tvb_reported_length_remaining(tvb, offset);
if (available < encoding_len) {
needed = (int) (encoding_len - available);
break;
}
offset += encoding_len;
}
/* content field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
} else {
uint32_t content_len = tvb_get_ntohl(tvb, offset);
offset += 4;
available = tvb_reported_length_remaining(tvb, offset);
if (available < content_len) {
needed = (int) (content_len - available);
break;
}
offset += content_len;
}
/* signature element field */
if ((flags & JXTAMSG1_ELMFLAG_SIGNATURE) != 0) {
tvbuff_t *jxta_signature_element_tvb;
int processed;
jxta_signature_element_tvb = tvb_new_subset_remaining(tvb, offset);
increment_dissection_depth(pinfo);
processed = dissect_jxta_message_element_1(jxta_signature_element_tvb, pinfo, NULL, 0, NULL);
decrement_dissection_depth(pinfo);
if (processed == 0) {
return offset;
}
if (processed < 0) {
needed = -processed;
break;
}
offset += processed;
}
break;
}
if ((needed > 0) && gDESEGMENT && pinfo->can_desegment) {
/* ws_message( "Element1 requesting %d more bytes", needed ); */
pinfo->desegment_offset = 0;
pinfo->desegment_len = needed;
return -needed;
}
/* Second pass : build the proto tree */
unsigned tree_offset = 0;
proto_item *jxta_elem_tree_item = proto_tree_add_item(tree, hf_jxta_element, tvb, tree_offset, -1, ENC_NA);
proto_tree *jxta_elem_tree = proto_item_add_subtree(jxta_elem_tree_item, ett_jxta_elem);
uint8_t namespaceID;
proto_item *namespace_ti;
uint16_t name_len;
uint32_t content_len;
char *mediatype = NULL;
tvbuff_t *element_content_tvb;
static int * const element_flags[] = {
&hf_jxta_element1_flag_hasType,
&hf_jxta_element1_flag_hasEncoding,
&hf_jxta_element1_flag_hasSignature,
NULL
};
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_sig, tvb, tree_offset, (int)sizeof(JXTA_MSGELEM_SIG), ENC_ASCII);
tree_offset += (int)sizeof(JXTA_MSGELEM_SIG);
namespaceID = tvb_get_uint8(tvb, tree_offset);
namespace_ti =
proto_tree_add_uint(jxta_elem_tree, hf_jxta_element1_namespaceid, tvb, tree_offset, 1, namespaceID);
if (namespaceID < ns_count) {
proto_item_append_text(namespace_ti, " (%s)", names_table[namespaceID]);
} else {
proto_item_append_text(namespace_ti, " * BAD *");
}
tree_offset += 1;
flags = tvb_get_uint8(tvb, tree_offset);
proto_tree_add_bitmask(jxta_elem_tree, tvb, tree_offset, hf_jxta_element_flags, ett_jxta_elem_1_flags, element_flags, ENC_NA);
tree_offset += 1;
name_len = tvb_get_ntohs(tvb, tree_offset);
proto_item_append_text(jxta_elem_tree_item, " \"%s\"", tvb_format_text(pinfo->pool, tvb, tree_offset + 2, name_len));
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_name, tvb, tree_offset, 2, ENC_ASCII|ENC_BIG_ENDIAN);
tree_offset += 2 + name_len;
/* process type */
if ((flags & JXTAMSG1_ELMFLAG_TYPE) != 0) {
uint16_t type_len = tvb_get_ntohs(tvb, tree_offset);
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_type, tvb, tree_offset, 2, ENC_ASCII|ENC_BIG_ENDIAN);
tree_offset += 2;
mediatype = tvb_get_string_enc(pinfo->pool, tvb, tree_offset, type_len, ENC_ASCII);
tree_offset += type_len;
}
/* process encoding */
if ((flags & JXTAMSG1_ELMFLAG_ENCODING) != 0) {
uint16_t encoding_len = tvb_get_ntohs(tvb, tree_offset);
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_encoding, tvb, tree_offset, 2, ENC_ASCII|ENC_BIG_ENDIAN);
tree_offset += 2 + encoding_len;
}
/* content */
content_len = tvb_get_ntohl(tvb, tree_offset);
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_content_len, tvb, tree_offset, 4, ENC_BIG_ENDIAN);
tree_offset += 4;
element_content_tvb = tvb_new_subset_length(tvb, tree_offset, content_len);
tree_offset += dissect_media(mediatype, element_content_tvb, pinfo, jxta_elem_tree);
/* process the signature element */
if ((flags & JXTAMSG1_ELMFLAG_SIGNATURE) != 0) {
tvbuff_t *jxta_message_element_tvb = tvb_new_subset_remaining(tvb, tree_offset);
increment_dissection_depth(pinfo);
tree_offset += dissect_jxta_message_element_1(jxta_message_element_tvb, pinfo, jxta_elem_tree, ns_count, names_table);
decrement_dissection_depth(pinfo);
}
proto_item_set_end(jxta_elem_tree_item, tvb, tree_offset);
// offset is based on reported lengths. tree_offset is based on captured lengths via dissect_media.
// Comment this out for now in favor of dissect_media's expert warning.
// DISSECTOR_ASSERT(tree_offset == offset);
return offset;
}
/**
* Dissect a tvbuff containing a JXTA Message Element (Version 2).
*
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @param names_count The number of elements in the names table.
* @param names_table The table of names.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized as a JXTA packet and negative if the
* dissector needs more bytes in order to process a PDU.
**/
// NOLINTNEXTLINE(misc-no-recursion)
static int dissect_jxta_message_element_2(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, unsigned names_count,
const char ** names_table)
{
unsigned offset = 0;
unsigned available;
int needed = 0;
uint8_t flags;
/* First pass. Make sure all of the bytes we need are available */
while (true) {
/* signature field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < sizeof(JXTA_MSGELEM_SIG)) {
needed = (int) (sizeof(JXTA_MSGELEM_SIG) - available);
}
if (tvb_memeql(tvb, offset, (const uint8_t*)JXTA_MSGELEM_SIG, sizeof(JXTA_MSGELEM_SIG)) != 0) {
/* It is not one of ours */
return 0;
}
offset += (int)sizeof(JXTA_MSGELEM_SIG);
/* flags field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 1) {
needed = 1;
break;
} else {
flags = tvb_get_uint8(tvb, offset);
offset++;
}
/* namespace id field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
}
offset += 2;
/* name field */
if ((flags & JXTAMSG2_ELMFLAG_NAME_LITERAL) == 0) {
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
}
offset += 2;
} else {
/* literal name field */
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
} else {
uint16_t name_len = tvb_get_ntohs(tvb, offset);
offset += 2;
available = tvb_reported_length_remaining(tvb, offset);
if (available < name_len) {
needed = (int) (name_len - available);
break;
}
offset += name_len;
}
}
/* type field */
if ((flags & JXTAMSG2_ELMFLAG_TYPE) != 0) {
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
}
offset += 2;
}
/* encoding field */
if ((flags & JXTAMSG2_ELMFLAG_ENCODINGS) != 0) {
available = tvb_reported_length_remaining(tvb, offset);
if (available < 2) {
needed = (int) (2 - available);
break;
}
offset += 2;
}
/* content field */
if ((flags & JXTAMSG2_ELMFLAG_UINT64_LENS) != 0) {
available = tvb_reported_length_remaining(tvb, offset);
if (available < sizeof(uint64_t)) {
needed = (int) (sizeof(uint64_t) - available);
break;
} else {
uint64_t content_len = tvb_get_ntoh64(tvb, offset);
offset += (int)sizeof(uint64_t);
available = tvb_reported_length_remaining(tvb, offset);
if (available < content_len) {
needed = (int) (content_len - available);
break;
}
offset += (unsigned) content_len;
}
} else {
available = tvb_reported_length_remaining(tvb, offset);
if (available < 4) {
needed = (int) (4 - available);
break;
} else {
uint64_t content_len = tvb_get_ntohl(tvb, offset);
offset += 4;
available = tvb_reported_length_remaining(tvb, offset);
if (available < content_len) {
needed = (int) (content_len - available);
break;
}
offset += (unsigned) content_len;
}
}
/* signature element field */
if ((flags & JXTAMSG2_ELMFLAG_SIGNATURE) != 0) {
tvbuff_t *jxta_signature_element_tvb;
int processed;
jxta_signature_element_tvb = tvb_new_subset_remaining(tvb, offset);
increment_dissection_depth(pinfo);
processed = dissect_jxta_message_element_2(jxta_signature_element_tvb, pinfo, NULL, 0, NULL);
decrement_dissection_depth(pinfo);
if (processed == 0) {
return offset;
}
if (processed < 0) {
needed = -processed;
break;
}
offset += processed;
}
break;
}
if ((needed > 0) && gDESEGMENT && pinfo->can_desegment) {
/* ws_message( "Element2 requesting %d more bytes", needed ); */
pinfo->desegment_offset = 0;
pinfo->desegment_len = needed;
return -needed;
}
/* Second (optional) pass : build the proto tree */
unsigned tree_offset = 0;
proto_item *jxta_elem_tree_item = proto_tree_add_item(tree, hf_jxta_element, tvb, tree_offset, -1, ENC_NA);
proto_tree *jxta_elem_tree = proto_item_add_subtree(jxta_elem_tree_item, ett_jxta_elem);
uint16_t namespaceID;
proto_item *namespace_ti;
uint16_t nameID;
proto_item *name_ti;
uint64_t content_len;
const char *mediatype = NULL;
tvbuff_t *element_content_tvb;
static int * const element_flags[] = {
&hf_jxta_element2_flag_64bitlens,
&hf_jxta_element2_flag_nameLiteral,
&hf_jxta_element2_flag_hasType,
&hf_jxta_element2_flag_hasSignature,
&hf_jxta_element2_flag_hasEncoding,
&hf_jxta_element2_flag_sigOfEncoded,
NULL
};
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_sig, tvb, tree_offset, (int)sizeof(JXTA_MSGELEM_SIG), ENC_ASCII);
tree_offset += (int)sizeof(JXTA_MSGELEM_SIG);
flags = tvb_get_uint8(tvb, tree_offset);
proto_tree_add_bitmask(jxta_elem_tree, tvb, tree_offset, hf_jxta_element_flags, ett_jxta_elem_2_flags, element_flags, ENC_NA);
tree_offset += 1;
/* Namespace */
namespaceID = tvb_get_ntohs(tvb, tree_offset);
namespace_ti =
proto_tree_add_uint(jxta_elem_tree, hf_jxta_element2_namespaceid, tvb, tree_offset, 2, namespaceID);
if (namespaceID < names_count) {
proto_item_append_text(namespace_ti, " (%s)", names_table[namespaceID]);
} else {
proto_item_append_text(namespace_ti, " * BAD *");
}
tree_offset += 2;
/* Name */
if ((flags & JXTAMSG2_ELMFLAG_NAME_LITERAL) == 0) {
nameID = tvb_get_ntohs(tvb, tree_offset);
name_ti =
proto_tree_add_uint(jxta_elem_tree, hf_jxta_element2_nameid, tvb, tree_offset, 2, nameID);
if (nameID < names_count) {
proto_item_append_text(name_ti, " (%s)", names_table[nameID]);
} else {
proto_item_append_text(name_ti, " * BAD *");
}
tree_offset += 2;
} else {
/* literal name */
uint16_t name_len = tvb_get_ntohs(tvb, tree_offset);
proto_item_append_text(jxta_elem_tree_item, " \"%s\"", tvb_format_text(pinfo->pool, tvb, tree_offset + 2, name_len));
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_name, tvb, tree_offset, 2, ENC_ASCII|ENC_BIG_ENDIAN);
tree_offset += 2 + name_len;
}
/* process type */
if ((flags & JXTAMSG2_ELMFLAG_TYPE) != 0) {
uint16_t mimeID = tvb_get_ntohs(tvb, tree_offset);
proto_item *mime_ti =
proto_tree_add_uint(jxta_elem_tree, hf_jxta_element2_mimeid, tvb, tree_offset, 2, mimeID);
if (mimeID < names_count) {
proto_item_append_text(mime_ti, " (%s)", names_table[mimeID]);
mediatype = wmem_strdup( pinfo->pool, names_table[mimeID] );
} else {
proto_item_append_text(mime_ti, " * BAD *");
}
tree_offset += 2;
} else {
mediatype = "application/octet-stream";
}
/* process encoding */
if ((flags & JXTAMSG2_ELMFLAG_ENCODINGS) != 0) {
uint16_t encodingID = tvb_get_ntohs(tvb, tree_offset);
proto_item *encoding_ti =
proto_tree_add_uint(jxta_elem_tree, hf_jxta_element2_encodingid, tvb, tree_offset, 2, encodingID);
if (encodingID < names_count) {
proto_item_append_text(encoding_ti, " (%s)", names_table[encodingID]);
} else {
proto_item_append_text(encoding_ti, " * BAD *");
}
tree_offset += 2;
}
if ((flags & JXTAMSG2_ELMFLAG_UINT64_LENS) != 0) {
content_len = tvb_get_ntoh64(tvb, tree_offset);
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_content_len64, tvb, tree_offset, 8, ENC_BIG_ENDIAN);
tree_offset += 8;
} else {
content_len = tvb_get_ntohl(tvb, tree_offset);
proto_tree_add_item(jxta_elem_tree, hf_jxta_element_content_len, tvb, tree_offset, 4, ENC_BIG_ENDIAN);
tree_offset += 4;
}
/* content */
element_content_tvb = tvb_new_subset_length(tvb, tree_offset, (int)content_len);
tree_offset += dissect_media(mediatype, element_content_tvb, pinfo, jxta_elem_tree);
/* process the signature element */
if ((flags & JXTAMSG2_ELMFLAG_SIGNATURE) != 0) {
tvbuff_t *jxta_message_element_tvb = tvb_new_subset_remaining(tvb, tree_offset);
tree_offset += dissect_jxta_message_element_1(jxta_message_element_tvb, pinfo, jxta_elem_tree, names_count, names_table);
}
proto_item_set_end(jxta_elem_tree_item, tvb, tree_offset);
// offset is based on reported lengths. tree_offset is based on captured lengths via dissect_media.
// Comment this out for now in favor of dissect_media's expert warning.
// DISSECTOR_ASSERT(tree_offset == offset);
return offset;
}
/**
* Dissect a tvbuff containing arbitrary typed data.
*
* <p/>We provide special handling for type media types :
* <dl>
* <dt>application/x-jxta-tls-block</dt>
* <dd>We hand this data off to SSL to dissect.</dd>
* <dt>application/gzip</dt>
* <dd>We decompress the data and then dissect the contents as <tt>text/xml;charset="UTF-8"</tt></dd>
* </dl>
*
* @param fullmediatype The full media type of the buffer to dissect including params
* @param tvb The buffer to dissect.
* @param pinfo Packet Info.
* @param tree The protocol tree.
* @return Number of bytes from the tvbuff_t which were processed, 0 (zero) if
* the packet was not recognized and negative if the dissector needs
* more bytes in order to process a PDU.
**/
// NOLINTNEXTLINE(misc-no-recursion)
static int dissect_media( const char* fullmediatype, tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree) {
int dissected = 0;
if (fullmediatype) {
char *mediatype = wmem_strdup(pinfo->pool, fullmediatype);
char *parms_at = strchr(mediatype, ';');
const char *save_match_string = pinfo->match_string;
media_content_info_t content_info = { MEDIA_CONTAINER_OTHER, NULL, NULL, NULL };
/* Based upon what is done in packet-media.c we set up type and params */
if (NULL != parms_at) {
content_info.media_str = wmem_strdup( pinfo->pool, parms_at + 1 );
*parms_at = '\0';
}
/* Set the version that goes to packet-media.c before converting case */
pinfo->match_string = wmem_strdup(pinfo->pool, mediatype);
/* force to lower case */
ascii_strdown_inplace(mediatype);
if (0 == strcmp("application/x-jxta-tls-block", mediatype)) {
/* If we recognize it as a TLS packet then we shuffle it off to tls dissector. */
if (NULL != tls_handle) {
dissected = call_dissector(tls_handle, tvb, pinfo, tree);
}
} else if (0 == strcmp("application/gzip", mediatype)) {
tvbuff_t *uncomp_tvb = tvb_child_uncompress_zlib(tvb, tvb, 0, tvb_captured_length(tvb));
if( NULL != uncomp_tvb ) {
add_new_data_source(pinfo, uncomp_tvb, "Uncompressed Element Content");
/* XXX bondolo 20060201 Force XML for uncompressed data. */
increment_dissection_depth(pinfo);
dissected = dissect_media("text/xml;charset=\"UTF-8\"", uncomp_tvb, pinfo, tree);
decrement_dissection_depth(pinfo);
if( dissected > 0 ) {
/* report back the uncompressed length. */
dissected = tvb_captured_length(tvb);
}
}
} else {
dissected = dissector_try_string(media_type_dissector_table, mediatype, tvb, pinfo, tree, &content_info) ? tvb_captured_length(tvb) : 0;
if( dissected != (int) tvb_captured_length(tvb) ) {
/* ws_message( "%s : %d expected, %d dissected", mediatype, tvb_captured_length(tvb), dissected ); */
}
}
if (0 == dissected) {
dissected = call_dissector_with_data(media_handle, tvb, pinfo, tree, &content_info);
}
pinfo->match_string = save_match_string;
}
if(0 == dissected) {
/* display it as raw data */
dissected = call_data_dissector(tvb, pinfo, tree);
}
if (dissected < (int) tvb_reported_length(tvb)) {
proto_item *item = proto_tree_add_expert(tree, pinfo, &ei_media_too_short, tvb, 0, dissected);
proto_item_set_generated(item);
}
return dissected;
}
/**
* Register jxta protocol and jxta message protocol, header fields, subtree types, preferences.
**/
void proto_register_jxta(void)
{
module_t *jxta_module;
expert_module_t *expert_jxta;
/** our header fields */
static hf_register_info hf[] = {
{&hf_uri_addr,
{"Address", "jxta.uri.addr", FT_STRING, BASE_NONE, NULL, 0x0,
"URI Address (source or destination)", HFILL}
},
{&hf_uri_src,
{"Source", "jxta.uri.src", FT_STRING, BASE_NONE, NULL, 0x0,
"URI Source", HFILL}
},
{&hf_uri_dst,
{"Destination", "jxta.uri.dst", FT_STRING, BASE_NONE, NULL, 0x0,
"URI Destination", HFILL}
},
{&hf_jxta_udp,
{"JXTA UDP", "jxta.udp", FT_NONE, BASE_NONE, NULL, 0x0,
NULL, HFILL}
},
{&hf_jxta_udpsig,
{"Signature", "jxta.udpsig", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA UDP Signature", HFILL}
},
{&hf_jxta_welcome,
{"Welcome", "jxta.welcome", FT_NONE, BASE_NONE, NULL, 0x00,
"JXTA Connection Welcome Message", HFILL}
},
{&hf_jxta_welcome_initiator,
{"Initiator", "jxta.welcome.initiator", FT_BOOLEAN, BASE_NONE, NULL, 0x00,
"JXTA Connection Welcome Message Initiator", HFILL}
},
{&hf_jxta_welcome_sig,
{"Signature", "jxta.welcome.signature", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message Signature", HFILL}
},
{&hf_jxta_welcome_destAddr,
{"Destination Address", "jxta.welcome.destAddr", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message Destination Address", HFILL}
},
{&hf_jxta_welcome_pubAddr,
{"Public Address", "jxta.welcome.pubAddr", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message Public Address", HFILL}
},
{&hf_jxta_welcome_peerid,
{"PeerID", "jxta.welcome.peerid", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message PeerID", HFILL}
},
{&hf_jxta_welcome_noProp,
{"No Propagate Flag", "jxta.welcome.noPropFlag", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message No Propagate Flag", HFILL}
},
{&hf_jxta_welcome_msgVers,
{"Preferred Message Version", "jxta.welcome.msgVersion", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message Preferred Message Version", HFILL}
},
{&hf_jxta_welcome_variable,
{"Variable Parameter", "jxta.welcome.variable", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message Variable Parameter", HFILL}
},
{&hf_jxta_welcome_version,
{"Version", "jxta.welcome.version", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Connection Welcome Message Version", HFILL}
},
{&hf_jxta_framing,
{"Framing", "jxta.framing", FT_NONE, BASE_NONE, NULL, 0x0,
"JXTA Message Framing", HFILL}
},
{&hf_jxta_framing_header,
{"Header", "jxta.framing.header", FT_NONE, BASE_NONE, NULL, 0x0,
"JXTA Message Framing Header", HFILL}
},
{&hf_jxta_framing_header_name,
{"Name", "jxta.framing.header.name", FT_UINT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Framing Header Name", HFILL}
},
{&hf_jxta_framing_header_value_length,
{"Value Length", "jxta.framing.header.valuelen", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Framing Header Value Length", HFILL}
},
{&hf_jxta_framing_header_value,
{"Value", "jxta.framing.header.value", FT_BYTES, BASE_NONE, NULL, 0x0,
"JXTA Message Framing Header Value", HFILL}
},
{&hf_jxta_message_address,
{"Address", "jxta.message.address", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Address (source or destination)", HFILL}
},
{&hf_jxta_message_src,
{"Source", "jxta.message.source", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Source", HFILL}
},
{&hf_jxta_message_dst,
{"Destination", "jxta.message.destination", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Destination", HFILL}
},
{&hf_jxta_message_sig,
{"Signature", "jxta.message.signature", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Signature", HFILL}
},
{&hf_jxta_message_version,
{"Version", "jxta.message.version", FT_UINT8, BASE_DEC, NULL, 0x0,
"JXTA Message Version", HFILL}
},
{&hf_jxta_message_flags,
{"Flags", "jxta.message.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
"JXTA Message Flags", HFILL}
},
{&hf_jxta_message_flag_utf16be,
{"UTF16BE", "jxta.message.flags.UTF-16BE", FT_BOOLEAN, 2, TFS(&tfs_set_notset), 0x1,
"JXTA Message Element Flag -- UTF16-BE Strings", HFILL}
},
{&hf_jxta_message_flag_ucs32be,
{"UCS32BE", "jxta.message.flags.UCS32BE", FT_BOOLEAN, 2, TFS(&tfs_set_notset), 0x2,
"JXTA Message Flag -- UCS32-BE Strings", HFILL}
},
{&hf_jxta_message_names_count,
{"Names Count", "jxta.message.names", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Names Table", HFILL}
},
{&hf_jxta_message_names_name,
{"Names Table Name", "jxta.message.names.name", FT_UINT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Names Table Name", HFILL}
},
{&hf_jxta_message_element_count,
{"Element Count", "jxta.message.elements", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Element Count", HFILL}
},
{&hf_jxta_element,
{"JXTA Message Element", "jxta.message.element", FT_NONE, BASE_NONE, NULL, 0x0,
NULL, HFILL}
},
{&hf_jxta_element_sig,
{"Signature", "jxta.message.element.signature", FT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Element Signature", HFILL}
},
{&hf_jxta_element1_namespaceid,
{"Namespace ID", "jxta.message.element.namespaceid", FT_UINT8, BASE_DEC, NULL, 0x0,
"JXTA Message Element Namespace ID", HFILL}
},
{&hf_jxta_element2_namespaceid,
{"Namespace ID", "jxta.message.element.namespaceid", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Element Namespace ID", HFILL}
},
{&hf_jxta_element_flags,
{"Flags", "jxta.message.element.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
"JXTA Message Element Flags", HFILL}
},
{&hf_jxta_element1_flag_hasType,
{"hasType", "jxta.message.element.flags.hasType", FT_BOOLEAN, 3, TFS(&tfs_set_notset), 0x1,
"JXTA Message Element Flag -- hasType", HFILL}
},
{&hf_jxta_element1_flag_hasEncoding,
{"hasEncoding", "jxta.message.element.flags.hasEncoding", FT_BOOLEAN, 3, TFS(&tfs_set_notset), 0x2,
"JXTA Message Element Flag -- hasEncoding", HFILL}
},
{&hf_jxta_element1_flag_hasSignature,
{"hasSignature", "jxta.message.element.flags.hasSignature", FT_BOOLEAN, 3, TFS(&tfs_set_notset), 0x4,
"JXTA Message Element Flag -- hasSignature", HFILL}
},
{&hf_jxta_element2_flag_64bitlens,
{"uint64Lens", "jxta.message.element.flags.uint64Lens", FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x01,
"JXTA Message Element Flag -- uint64Lens", HFILL}
},
{&hf_jxta_element2_flag_nameLiteral,
{"nameLiteral", "jxta.message.element.flags.nameLiteral", FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x02,
"JXTA Message Element Flag -- nameLiteral", HFILL}
},
{&hf_jxta_element2_flag_hasType,
{"hasType", "jxta.message.element.flags.hasType", FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x04,
"JXTA Message Element Flag -- hasType", HFILL}
},
{&hf_jxta_element2_flag_hasSignature,
{"hasSignature", "jxta.message.element.flags.hasSignature", FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x08,
"JXTA Message Element Flag -- hasSignature", HFILL}
},
{&hf_jxta_element2_flag_hasEncoding,
{"hasSignature", "jxta.message.element.flags.hasEncoding", FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x10,
"JXTA Message Element Flag -- hasEncoding", HFILL}
},
{&hf_jxta_element2_flag_sigOfEncoded,
{"sigOfEncoded", "jxta.message.element.flags.sigOfEncoded", FT_BOOLEAN, 6, TFS(&tfs_set_notset), 0x20,
"JXTA Message Element Flag -- sigOfEncoded", HFILL}
},
{&hf_jxta_element2_nameid,
{"Name ID", "jxta.message.element.nameid", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Element Name ID", HFILL}
},
{&hf_jxta_element_name,
{"Element Name", "jxta.message.element.name", FT_UINT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Element Name", HFILL}
},
{&hf_jxta_element2_mimeid,
{"MIME ID", "jxta.message.element.mimeid", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Element MIME ID", HFILL}
},
{&hf_jxta_element2_encodingid,
{"Encoding ID", "jxta.message.element.encodingid", FT_UINT16, BASE_DEC, NULL, 0x0,
"JXTA Message Element Encoding ID", HFILL}
},
{&hf_jxta_element_type,
{"Element Type", "jxta.message.element.type", FT_UINT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Element Name", HFILL}
},
{&hf_jxta_element_encoding,
{"Element Type", "jxta.message.element.encoding", FT_UINT_STRING, BASE_NONE, NULL, 0x0,
"JXTA Message Element Encoding", HFILL}
},
{&hf_jxta_element_content_len,
{"Element Content Length", "jxta.message.element.content.length", FT_UINT32, BASE_DEC, NULL, 0x0,
"JXTA Message Element Content Length", HFILL}
},
{&hf_jxta_element_content_len64,
{"Element Content Length", "jxta.message.element.content.length64", FT_UINT64, BASE_DEC, NULL, 0x0,
"JXTA Message Element Content Length", HFILL}
},
#if 0
{&hf_jxta_element_content,
{"Element Content", "jxta.message.element.content", FT_BYTES, BASE_NONE, NULL, 0x0,
"JXTA Message Element Content", HFILL}
},
#endif
};
static ei_register_info ei[] = {
{ &ei_media_too_short, { "jxta.media_too_short", PI_PROTOCOL, PI_WARN, "Media length less than expected", EXPFILL }},
};
/**
* JXTA Protocol subtree array
**/
static int *ett[] = {
&ett_jxta,
&ett_jxta_welcome,
&ett_jxta_udp,
&ett_jxta_framing,
&ett_jxta_framing_header,
&ett_jxta_msg,
&ett_jxta_msg_flags,
&ett_jxta_elem,
&ett_jxta_elem_1_flags,
&ett_jxta_elem_2_flags
};
proto_jxta = proto_register_protocol("JXTA P2P", "JXTA", "jxta");
jxta_tap = register_tap("jxta");
proto_message_jxta = proto_register_protocol("JXTA Message", "JXTA Message", "jxta.message");
jxta_udp_handle = register_dissector("jxta.udp", dissect_jxta_udp, proto_jxta);
stream_jxta_handle = register_dissector("jxta.stream", dissect_jxta_stream, proto_jxta);
/* Register header fields */
proto_register_field_array(proto_jxta, hf, array_length(hf));
/* Register JXTA Sub-tree */
proto_register_subtree_array(ett, array_length(ett));
expert_jxta = expert_register_protocol(proto_jxta);
expert_register_field_array(expert_jxta, ei, array_length(ei));
uri_address_type = address_type_dissector_register("AT_URI", "URI/URL/URN", uri_to_str, uri_str_len, NULL, uri_col_filter_str, NULL, NULL, NULL);
/* Register preferences */
/* register re-init routine */
jxta_module = prefs_register_protocol(proto_jxta, proto_reg_handoff_jxta);
prefs_register_bool_preference(jxta_module, "msg.mediatype", "Register binary JXTA Message as a media type",
"Enable to have correctly typed MIME media dissected as JXTA Messages.", &gMSG_MEDIA);
prefs_register_bool_preference(jxta_module, "desegment",
"Reassemble JXTA messages spanning multiple UDP/TCP/SCTP segments",
"Whether the JXTA dissector should reassemble messages spanning multiple UDP/TCP/SCTP segments."
" To use this option you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings "
" and enable \"Reassemble fragmented IP datagrams\" in the IP protocol settings.",
&gDESEGMENT);
prefs_register_obsolete_preference(jxta_module, "udp.heuristic");
prefs_register_obsolete_preference(jxta_module, "tcp.heuristic");
prefs_register_obsolete_preference(jxta_module, "sctp.heuristic");
register_conversation_table(proto_jxta, true, jxta_conversation_packet, jxta_endpoint_packet);
}
/**
* Update registrations in response to preferences changes.
**/
void proto_reg_handoff_jxta(void)
{
static bool init_done = false;
static dissector_handle_t message_jxta_handle;
static bool msg_media_register_done = false;
if(!init_done) {
message_jxta_handle = create_dissector_handle(dissect_jxta_message, proto_message_jxta);
media_type_dissector_table = find_dissector_table("media_type");
tls_handle = find_dissector_add_dependency("tls", proto_jxta);
media_handle = find_dissector_add_dependency("media", proto_jxta);
heur_dissector_add("udp", dissect_jxta_UDP_heur, "JXTA over UDP", "jxta_udp", proto_jxta, HEURISTIC_ENABLE);
heur_dissector_add("tcp", dissect_jxta_TCP_heur, "JXTA over TCP", "jxta_tcp", proto_jxta, HEURISTIC_ENABLE);
heur_dissector_add("sctp", dissect_jxta_SCTP_heur, "JXTA over SCTP", "jxta_sctp", proto_jxta, HEURISTIC_ENABLE);
init_done = true;
}
if( gMSG_MEDIA ) {
if( !msg_media_register_done ) {
/* ws_message( "Registering JXTA Message media type" ); */
dissector_add_string("media_type", "application/x-jxta-msg", message_jxta_handle);
msg_media_register_done = true;
}
} else {
if( msg_media_register_done ) {
/* ws_message( "Deregistering JXTA Message media type" ); */
dissector_delete_string("media_type", "application/x-jxta-msg", message_jxta_handle);
msg_media_register_done = false;
}
}
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|