dahdi_pcap: Allow caller to specify network / user mode

A LAPD dissector (such as the one in wireshark) needs to know if
the local side is the user or the network in order to properly
decode/display the trace.  This is encoded in the sll_addr field
whose first octet indicates if the local (capturing) node serves
as the network or user side of ISDN.

Change-Id: Ief575bc4118fe5f20ef4b374d29eca442b04dabb
This commit is contained in:
Harald Welte 2022-02-21 20:47:07 +01:00
parent de9bd096c9
commit e9a4598c1f
1 changed files with 22 additions and 9 deletions

View File

@ -101,7 +101,7 @@ int make_mirror(long type, int chan)
return fd;
}
int log_packet(struct chan_fds * fd, char is_read, pcap_dumper_t * dump)
int log_packet(struct chan_fds * fd, char is_read, int we_are_network, pcap_dumper_t * dump)
{
unsigned char buf[BLOCK_SIZE * 4];
int res = 0;
@ -165,7 +165,7 @@ int log_packet(struct chan_fds * fd, char is_read, pcap_dumper_t * dump)
lapd->sll_pkttype = htons(is_read ? PACKET_HOST : PACKET_OUTGOING);
lapd->sll_hatype = 0;
lapd->sll_halen = htons(8);
// lapd->sll_addr = ???
lapd->sll_addr[0] = we_are_network;
lapd->sll_protocol[0] = 0x00;
lapd->sll_protocol[1] = 0x30;
@ -200,6 +200,7 @@ void usage()
printf("Options:\n");
printf(" -p, --proto=[mtp2|lapd] The protocol to capture, default mtp2\n");
printf(" -c, --chan=<channels> Comma separated list of channels to capture from, max %d. Mandatory\n", MAX_CHAN);
printf(" -r, --role=[network|user] Is the local side the network or user side in ISDN?\n");
printf(" -f, --file=<filename> The pcap file to capture to. Mandatory\n");
printf(" -h, --help Display this text\n");
}
@ -211,6 +212,7 @@ int main(int argc, char **argv)
int num_chans = 0;
int max_fd = 0;
int proto = DLT_MTP2_WITH_PHDR;
int we_are_network = 0;
int i;
int packetcount;
@ -221,12 +223,13 @@ int main(int argc, char **argv)
static struct option long_options[] = {
{"proto", required_argument, 0, 'p'},
{"chan", required_argument, 0, 'c'},
{"role", required_argument, 0, 'r'},
{"file", required_argument, 0, 'f'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "p:c:f:?",
c = getopt_long(argc, argv, "p:c:r:f:?",
long_options, &option_index);
if (c == -1)
break;
@ -269,6 +272,16 @@ int main(int argc, char **argv)
}
max_fd++;
break;
case 'r':
if (!strcasecmp("network", optarg))
we_are_network = 1;
else if (!strcasecmp("user", optarg))
we_are_network = 0;
else {
fprintf(stderr, "Role must be user or network!\n");
exit(1);
}
break;
case 'f':
// File to capture to
filename=optarg;
@ -318,11 +331,11 @@ int main(int argc, char **argv)
{
if(FD_ISSET(chans[i].rfd, &rd_set))
{
packetcount += log_packet(&chans[i], 1, dump);
packetcount += log_packet(&chans[i], 1, we_are_network, dump);
}
if(FD_ISSET(chans[i].tfd, &rd_set))
{
packetcount += log_packet(&chans[i], 0, dump);
packetcount += log_packet(&chans[i], 0, we_are_network, dump);
}
}
printf("Packets captured: %d\r", packetcount);