Project

General

Profile

Feature #385 ยป 0004-batadv-Add-support-for-ELP-packets.patch

Sven Eckelmann, 06/09/2019 09:22 PM

View differences:

epan/dissectors/packet-batadv.c
37 37
#define BATADV_IV_OGM_V15        0x00
38 38
#define BATADV_BCAST_V15         0x01
39 39
#define BATADV_CODED_V15         0x02
40
#define BATADV_ELP_V15           0x03
40 41
#define BATADV_UNICAST_V15       0x40
41 42
#define BATADV_UNICAST_FRAG_V15  0x41
42 43
#define BATADV_UNICAST_4ADDR_V15 0x42
......
184 185
};
185 186
#define IV_OGM_PACKET_V15_SIZE 24
186 187

  
188
struct elp_packet_v15 {
189
	guint8  packet_type;
190
	guint8  version;
191
	address orig;
192
	guint32 seqno;
193
	guint32 interval;
194
};
195
#define ELP_PACKET_V15_SIZE 16
196

  
187 197
struct icmp_packet_v6 {
188 198
	guint8  packet_type;
189 199
	guint8  version;  /* batman version field */
......
454 464
static gint ett_batadv_batman_tt = -1;
455 465
static gint ett_batadv_iv_ogm = -1;
456 466
static gint ett_batadv_iv_ogm_flags = -1;
467
static gint ett_batadv_elp = -1;
457 468
static gint ett_batadv_bcast = -1;
458 469
static gint ett_batadv_icmp = -1;
459 470
static gint ett_batadv_icmp_rr = -1;
......
511 522
static int hf_batadv_iv_ogm_tq = -1;
512 523
static int hf_batadv_iv_ogm_tvlv_len = -1;
513 524

  
525
static int hf_batadv_elp_version = -1;
526
static int hf_batadv_elp_orig = -1;
527
static int hf_batadv_elp_seqno = -1;
528
static int hf_batadv_elp_interval = -1;
529

  
514 530
static int hf_batadv_bcast_version = -1;
515 531
static int hf_batadv_bcast_orig = -1;
516 532
static int hf_batadv_bcast_seqno = -1;
......
798 814
static void dissect_batadv_iv_ogm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
799 815
static int dissect_batadv_iv_ogm_v15(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
800 816

  
817
static void dissect_batadv_elp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
818
static void dissect_batadv_elp_v15(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
819

  
801 820
static void dissect_batadv_bcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
802 821
static void dissect_batadv_bcast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
803 822
static void dissect_batadv_bcast_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
......
953 972
	case BATADV_CODED_V15:
954 973
		dissect_batadv_coded(tvb, pinfo, tree);
955 974
		break;
975
	case BATADV_ELP_V15:
976
		dissect_batadv_elp(tvb, pinfo, tree);
977
		break;
956 978
	case BATADV_UNICAST_V15:
957 979
		dissect_batadv_unicast(tvb, pinfo, tree);
958 980
		break;
......
3904 3926
	}
3905 3927
}
3906 3928

  
3929
static void dissect_batadv_elp(tvbuff_t *tvb, packet_info *pinfo,
3930
			       proto_tree *tree)
3931
{
3932
	guint8 version;
3933

  
3934
	/* set protocol name */
3935
	col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_ELP");
3936

  
3937
	version = tvb_get_guint8(tvb, 1);
3938
	switch (version) {
3939
	case 15:
3940
		dissect_batadv_elp_v15(tvb, pinfo, tree);
3941
		break;
3942
	default:
3943
		col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported Version %d",
3944
			     version);
3945
		call_data_dissector(tvb, pinfo, tree);
3946
		break;
3947
	}
3948
}
3949

  
3950
static void dissect_batadv_elp_v15(tvbuff_t *tvb, packet_info *pinfo,
3951
				   proto_tree *tree)
3952
{
3953
	struct elp_packet_v15 *elp_packeth;
3954
	proto_tree *batadv_elp_tree = NULL;
3955

  
3956
	tvbuff_t *next_tvb;
3957
	gint length_remaining;
3958
	int offset = 0;
3959

  
3960
	elp_packeth = (struct elp_packet_v15 *)wmem_alloc(wmem_packet_scope(),
3961
							  sizeof(struct elp_packet_v15));
3962

  
3963
	/* Set tree info */
3964
	if (tree) {
3965
		proto_item *ti;
3966

  
3967
		ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin,
3968
						    tvb, 0,
3969
						    ELP_PACKET_V15_SIZE,
3970
						    "B.A.T.M.A.N. ELP");
3971
		batadv_elp_tree = proto_item_add_subtree(ti, ett_batadv_elp);
3972
	}
3973

  
3974
	/* items */
3975
	elp_packeth->packet_type = tvb_get_guint8(tvb, offset);
3976
	proto_tree_add_uint_format_value(batadv_elp_tree,
3977
					 hf_batadv_packet_type,
3978
					 tvb, offset, 1,
3979
					 elp_packeth->packet_type,
3980
					 "%s (%u)", "BATADV_ELP",
3981
					 elp_packeth->packet_type);
3982
	offset += 1;
3983

  
3984
	elp_packeth->version = tvb_get_guint8(tvb, offset);
3985
	proto_tree_add_item(batadv_elp_tree, hf_batadv_elp_version, tvb,
3986
			    offset, 1, ENC_BIG_ENDIAN);
3987
	offset += 1;
3988

  
3989
	set_address_tvb(&elp_packeth->orig, AT_ETHER, 6, tvb, offset);
3990
	set_address_tvb(&pinfo->dl_src, AT_ETHER, 6, tvb, offset);
3991
	set_address_tvb(&pinfo->src, AT_ETHER, 6, tvb, offset);
3992
	proto_tree_add_item(batadv_elp_tree, hf_batadv_elp_orig, tvb,
3993
			    offset, 6, ENC_NA);
3994
	offset += 6;
3995

  
3996
	elp_packeth->seqno = tvb_get_ntohl(tvb, offset);
3997
	proto_tree_add_item(batadv_elp_tree, hf_batadv_elp_seqno, tvb,
3998
			    offset, 4, ENC_BIG_ENDIAN);
3999
	offset += 4;
4000

  
4001
	elp_packeth->interval = tvb_get_ntohl(tvb, offset);
4002
	proto_tree_add_item(batadv_elp_tree, hf_batadv_elp_interval, tvb,
4003
			    offset, 4, ENC_BIG_ENDIAN);
4004
	offset += 4;
4005

  
4006
	tap_queue_packet(batadv_tap, pinfo, elp_packeth);
4007

  
4008
	length_remaining = tvb_reported_length_remaining(tvb, offset);
4009
	if (length_remaining > 0) {
4010
		next_tvb = tvb_new_subset_remaining(tvb, offset);
4011

  
4012
		if (have_tap_listener(batadv_follow_tap)) {
4013
			tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
4014
		}
4015

  
4016
		call_data_dissector(next_tvb, pinfo, tree);
4017
	}
4018
}
4019

  
3907 4020
static void dissect_batadv_unicast_tvlv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
3908 4021
{
3909 4022
	guint8 version;
......
4576 4689
		    FT_ETHER, BASE_NONE, NULL, 0x0,
4577 4690
		    NULL, HFILL }
4578 4691
		},
4692
		{ &hf_batadv_elp_version,
4693
		  { "Version", "batadv.elp.version",
4694
		    FT_UINT8, BASE_DEC, NULL, 0x0,
4695
		    NULL, HFILL }
4696
		},
4697
		{ &hf_batadv_elp_orig,
4698
		  { "Originator", "batadv.elp.orig",
4699
		    FT_ETHER, BASE_NONE, NULL, 0x0,
4700
		    NULL, HFILL }
4701
		},
4702
		{ &hf_batadv_elp_seqno,
4703
		  { "Sequence number", "batadv.elp.seq",
4704
		    FT_UINT32, BASE_DEC, NULL, 0x0,
4705
		    NULL, HFILL }
4706
		},
4707
		{ &hf_batadv_elp_interval,
4708
		  { "ELP Interval", "batadv.elp.interval",
4709
		    FT_UINT32, BASE_DEC, NULL, 0x0,
4710
		    NULL, HFILL }
4711
		},
4579 4712
		{ &hf_batadv_bcast_version,
4580 4713
		  { "Version", "batadv.bcast.version",
4581 4714
		    FT_UINT8, BASE_DEC, NULL, 0x0,
......
5229 5362
		&ett_batadv_batman_gwflags,
5230 5363
		&ett_batadv_iv_ogm,
5231 5364
		&ett_batadv_iv_ogm_flags,
5365
		&ett_batadv_elp,
5232 5366
		&ett_batadv_bcast,
5233 5367
		&ett_batadv_icmp,
5234 5368
		&ett_batadv_icmp_rr,
    (1-1/1)