forked from tabacha/ProSafeLinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsl_typ.py
860 lines (673 loc) · 24.7 KB
/
psl_typ.py
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
# -*- coding: utf-8 -*-
"Base Types for ProSafeLinux Class"
import binascii
import struct
class PslTyp:
"Base type every other type is inherited by this"
def __init__(self, cmd_id, name):
"constructor"
self.cmd_id = cmd_id
self.name = name
def get_id(self):
"id of the command used by the switch to identify the command"
return self.cmd_id
def get_name(self):
"name used by humans to identify the command"
return self.name
def pack_py(self, value):
"pack a value to a represenation used by the switch"
raise NotImplementedError
def unpack_py(self, value):
"unpack a switch value to a represenation used by the programm"
raise NotImplementedError
def pack_cmd(self, value):
"pack something given from the cmd line"
raise NotImplementedError
def unpack_cmd(self, value):
"unpack something given from the cmd line"
raise NotImplementedError
def print_result(self, value):
"print a result for a query action"
print("%-30s%s" % (self.get_name().capitalize(), value))
def is_setable(self):
"can this command be set like name (not like firmware version)"
return False
def is_queryable(self):
"can the command be queryed like name (not like reboot switch)"
return True
def get_choices(self):
"if there is more than one choice you can query it here"
return None
def get_num_args(self):
"Number of arguments needed to set"
return 1
def get_metavar(self):
"argparse metavar to set"
return None
def get_set_type(self):
"argparse type to set"
return None
def get_set_help(self):
"argparse help argument for set operation"
return None
###############################################################################
class PslTypString(PslTyp):
"A String typ line name"
def pack_py(self, value):
return value.encode()
def unpack_py(self, value):
return value.decode()
def pack_cmd(self, value):
return value.encode()
def unpack_cmd(self, value):
value = value.split(b"\0", 1)[0]
return value.decode()
def is_setable(self):
return True
###############################################################################
class PslTypStringQueryOnly(PslTypString):
"a string type which can only be queried but not changed like firmware ver."
def is_setable(self):
return False
###############################################################################
class PslTypPassword(PslTypString):
"a password can be set, but not queried"
def __init__(self, cmd_id, name, setable):
PslTypString.__init__(self, cmd_id, name)
self.setable = setable
def is_queryable(self):
return False
def is_setable(self):
return self.setable
################################################################################
class PslTypBoolean(PslTyp):
" A boolean type, like dhcp on or off"
def pack_py(self, value):
if (value):
return struct.pack(">b", 0x01)
else:
return struct.pack(">b", 0x00)
def unpack_py(self, value):
if len(value)==1:
numval = struct.unpack(">b", value)[0]
else:
numval = struct.unpack(">h",value)[0]
return (numval == 0x01)
def pack_cmd(self, value):
return self.pack_py(value.lowercase == "on")
def unpack_cmd(self, value):
if (self.unpack_py(value)):
return "on"
else:
return "off"
def is_setable(self):
return True
def get_choices(self):
return ["on", "off"]
###############################################################################
class PslTypDHCP(PslTypBoolean):
"DHCP"
# we already have that in base PslTypBoolean class, haven't we ?
# def pack_py(self, value):
# if (value):
# # DHCP on
# return struct.pack(">b", 0x01)
# else:
# return struct.pack(">b", 0x00)
###############################################################################
class PslTypAction(PslTypBoolean):
"An action like reset or reboot switch"
def pack_py(self, value):
return struct.pack(">b", 0x01)
def is_queryable(self):
return False
def is_setable(self):
return True
###############################################################################
class PslTypMac(PslTyp):
"the mac address"
def pack_py(self, val):
if (len(val) == 17):
return binascii.unhexlify(val[0:2] + val[3:5] + val[6:8] +
val[9:11] + val[12:14] + val[15:17])
if (len(val) == 12):
return binascii.unhexlify(val)
raise "unkown mac format=" + val
def unpack_py(self, value):
mac = binascii.hexlify(value)
mac = mac.decode() # binascii.hexlify() yields a byte list in Python 3
return (mac[0:2] + ":" + mac[2:4] + ":" + mac[4:6] + ":" + mac[6:8] +
":" + mac[8:10] + ":" + mac[10:12])
def pack_cmd(self, value):
return self.pack_py(value)
def unpack_cmd(self, value):
return self.unpack_py(value)
################################################################################
class PslTypIpv4(PslTyp):
"IPv4 adrresss, gateway or netmask"
def pack_py(self, value):
adr = value.split(".")
if len(adr)!= 4:
raise ValueError("IP address wrong format %s" % value)
for i in range(4):
try:
num = int(adr[i])
except ValueError:
raise ValueError("IP address wrong format %s (String?)" % value)
if num > 255:
raise ValueError("IP address wrong format %s (>255)" % value)
if num < 0:
raise ValueError("IP address wrong format %s (<0)" % value)
return struct.pack(">BBBB", int(adr[0]), int(adr[1]), int(adr[2]),
int(adr[3]))
def unpack_py(self, value):
adr = struct.unpack(">BBBB", value)
return "%d.%d.%d.%d" % (adr[0], adr[1], adr[2], adr[3])
def pack_cmd(self, value):
return self.pack_py(value)
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
################################################################################
class PslTypHex(PslTyp):
"just decode to hex"
def pack_py(self, value):
return binascii.unhexlify(value)
def unpack_py(self, value):
return binascii.hexlify(value).decode()
def pack_cmd(self, value):
return self.pack_py(value)
def unpack_cmd(self, value):
return self.unpack_py(value)
################################################################################
class PslTypUnknown(PslTypHex):
"Unknown Data"
def unpack_cmd(self, value):
return "Unknown: %s - %s" % (self.name, binascii.hexlify(value))
################################################################################
class PslTypHexNoQuery(PslTypHex):
"not query hex"
def is_queryable(self):
return False
################################################################################
class PslTypEnd(PslTypHex):
"the last cmd of an query is End"
def is_setable(self):
return False
def is_queryable(self):
return False
def print_result(self, value):
pass
################################################################################
class PslTypSpeedStat(PslTyp):
"Speed statistic 10/100/1000 per port"
SPEED_NONE = 0x00
SPEED_10MH = 0x01
SPEED_10ML = 0x02
SPEED_100MH = 0x03
SPEED_100ML = 0x04
SPEED_1G = 0x05
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
rtn = {
"port": struct.unpack(">b", value[0])[0],
"speed": struct.unpack(">b", value[1])[0],
"rest": binascii.hexlify(value[2:]),
}
else:
rtn = {
"port": value[0],
"speed": value[1],
"rest": binascii.hexlify(value[2:]).decode(),
}
return rtn
def is_setable(self):
return False
def print_result(self, value):
print("%-30s%4s%15s%10s" % ("Speed Statistic:", "Port",
"Speed", "FIXME"))
for row in value:
speed = row["speed"]
if speed == PslTypSpeedStat.SPEED_NONE:
speed = "Not conn."
if speed == PslTypSpeedStat.SPEED_10MH:
speed = "10 Mbit/s H"
if speed == PslTypSpeedStat.SPEED_10ML:
speed = "10 Mbit/s L"
if speed == PslTypSpeedStat.SPEED_100MH:
speed = "100 Mbit/s H"
if speed == PslTypSpeedStat.SPEED_100ML:
speed = "100 Mbit/s L"
if speed == PslTypSpeedStat.SPEED_1G:
speed = "1 Gbit/s"
print("%-30s%4d%15s%10s" % ("", row["port"], speed, row["rest"]))
def unpack_cmd(self, value):
return self.unpack_py(value)
################################################################################
class PslTypPortStat(PslTyp):
"how many bytes are received/send on each port"
def unpack_py(self, val):
# Python 3 uses an array of bytes, Python 2 uses a string
values = struct.unpack("!b6Q", val)
rtn = {
"port": values[0],
"rec": values[1],
"send": values[2],
"pkt": values[3],
"bcst": values[4],
"mcst": values[5],
"error": values[6]
}
return rtn
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return False
def print_result(self, value):
print("%-30s%4s%15s%15s%15s%15s%15s%15s" % ("Port Statistic:", "Port",
"Rec.", "Send", "Packets",
"Broadcast pkt", "Multicast pkt",
"CRC errors"))
for row in value:
print("%-30s%4d%15d%15d%15d%15d%15d%15d" % ("",
row["port"], row["rec"],
row["send"], row["pkt"],
row["bcst"], row["mcst"],
row["error"]))
################################################################################
class PslTypBandwidth(PslTyp):
"limit bandwidth"
SPEED_LIMIT_NONE = 0x0000
SPEED_LIMIT_512K = 0x0001
SPEED_LIMIT_1M = 0x0002
SPEED_LIMIT_2M = 0x0003
SPEED_LIMIT_4M = 0x0004
SPEED_LIMIT_8M = 0x0005
SPEED_LIMIT_16M = 0x0006
SPEED_LIMIT_32M = 0x0007
SPEED_LIMIT_64M = 0x0008
SPEED_LIMIT_128M = 0x0009
SPEED_LIMIT_256M = 0x000a
SPEED_LIMIT_512M = 0x000b
speed_to_string = {
SPEED_LIMIT_NONE: " NONE ",
SPEED_LIMIT_512K: " 0.5M",
SPEED_LIMIT_1M: " 1.0M",
SPEED_LIMIT_2M: " 2.0M",
SPEED_LIMIT_4M: " 4.0M",
SPEED_LIMIT_8M: " 8.0M",
SPEED_LIMIT_16M: " 16.0M",
SPEED_LIMIT_32M: " 32.0M",
SPEED_LIMIT_64M: " 64.0M",
SPEED_LIMIT_128M: "128.0M",
SPEED_LIMIT_256M: "256.0M",
SPEED_LIMIT_512M: "512.0M"
}
string_to_speed = {
"NONE":SPEED_LIMIT_NONE,
"512K":SPEED_LIMIT_512K,
"1M":SPEED_LIMIT_1M,
"2M":SPEED_LIMIT_2M,
"4M":SPEED_LIMIT_4M,
"8M":SPEED_LIMIT_8M,
"16M":SPEED_LIMIT_16M,
"32M":SPEED_LIMIT_32M,
"64M":SPEED_LIMIT_64M,
"128M":SPEED_LIMIT_128M,
"256M":SPEED_LIMIT_256M,
"512M":SPEED_LIMIT_512M
}
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
rtn = {
"port": struct.unpack(">b", value[0])[0],
"limit": struct.unpack(">h", value[3::])[0],
"rest": binascii.hexlify(value[1:3]),
}
else:
rtn = {
"port": value[0],
"limit": struct.unpack(">h", value[3::])[0],
"rest": binascii.hexlify(value[1:3]).decode(),
}
return rtn
def pack_py(self, value):
limit = self.string_to_speed[value[1]]
rtn = struct.pack(">bbbh", int(value[0]), 0, 0, limit)
return rtn
def print_result(self, value):
print("%-30s%4s%15s %s" % (self.get_name().capitalize(), "Port",
"Limit", "FIXME"))
for row in value:
print("%-30s%4d%15s %s " % ("",
row["port"],
self.speed_to_string[row["limit"]],
row["rest"]))
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_num_args(self):
return 2
def get_metavar(self):
return ("PORT", "LIMIT")
def get_set_help(self):
out = "LIMIT can be: NONE,512K,1M,2M,4M,16M,32M,64M,128M,256M,512M"
return out
################################################################################
class PslTypVlanId(PslTyp):
"Vlan ports are binary coded"
BIN_PORTS = {1: 0x80,
2: 0x40,
3: 0x20,
4: 0x10,
5: 0x08,
6: 0x04,
7: 0x02,
8: 0x01
}
def unpack_py(self, value):
ports = struct.unpack(">B", value[2:])[0]
out_ports = []
for port in list(self.BIN_PORTS.keys()):
if (ports & self.BIN_PORTS[port] > 0):
out_ports.append(port)
rtn = {
"vlan_id": struct.unpack(">h", value[0:2])[0],
"ports": out_ports
}
return rtn
def pack_port(self, ports):
"helper method to pack ports to binary"
rtn = 0
if ports == "":
return rtn
for port in ports.split(","):
rtn = rtn + self.BIN_PORTS[int(port)]
return rtn
def pack_py(self, value):
ports = self.pack_port(value[1])
rtn = struct.pack(">hB", int(value[0]), ports)
return rtn
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_num_args(self):
return 2
def get_metavar(self):
return ("VLAN_ID", "PORTS")
def print_result(self, value):
print("%-30s%7s %s" % (self.get_name().capitalize(), "VLAN_ID",
"Ports"))
for row in value:
print("%-30s%7d %s" % ("",
int(row["vlan_id"]),
",".join([str(x) for x in row["ports"]])))
################################################################################
class PslTypVlan802Id(PslTypVlanId):
"802Vlan is binary coded"
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
tagged_ports = struct.unpack(">B", value[2])[0]
untagged_ports = struct.unpack(">B", value[3])[0]
else:
tagged_ports = value[2]
untagged_ports = value[3]
out_tagged_ports = []
out_untagged_ports = []
for port in list(self.BIN_PORTS.keys()):
if (tagged_ports & self.BIN_PORTS[port] > 0):
out_tagged_ports.append(port)
if (untagged_ports & self.BIN_PORTS[port] > 0):
out_untagged_ports.append(port)
rtn = {
"vlan_id": struct.unpack(">h", value[0:2])[0],
"tagged_ports": out_tagged_ports,
"untagged_ports": out_untagged_ports
}
return rtn
def pack_py(self, value):
tagged = self.pack_port(value[1])
untagged = self.pack_port(value[2])
rtn = struct.pack(">hBB", int(value[0]), tagged, untagged)
return rtn
def unpack_cmd(self, value):
return self.unpack_py(value)
def get_num_args(self):
return 3
def get_metavar(self):
return ("VLAN_ID", "TAGGED_PORTS", "UNTAGGED_PORTS")
def print_result(self, value):
print("%-30s%7s %14s %s" % (self.get_name().capitalize(), "VLAN_ID",
"Tagged-Ports","Untagged-Ports"))
if type(value) is list:
for row in value:
print("%-30s%7d %14s %s" % ("",
int(row["vlan_id"]),
",".join([str(x) for x in row["tagged_ports"]]),
",".join([str(x) for x in row["untagged_ports"]])))
else:
print("%-30s%7d %14s %s" % ("",
int(value["vlan_id"]),
",".join([str(x) for x in value["tagged_ports"]]),
",".join([str(x) for x in value["untagged_ports"]])))
################################################################################
class PslTypVlanPVID(PslTyp):
"The PVID"
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
rtn = {
"port": struct.unpack(">B", value[0])[0],
"vlan_id": struct.unpack(">h", value[1:])[0]
}
else:
rtn = {
"port": value[0],
"vlan_id": struct.unpack(">h", value[1:])[0]
}
return rtn
def pack_py(self, value):
# value = value.encode()
rtn = struct.pack(">Bh", int(value[0]), int(value[1]))
return rtn
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_num_args(self):
return 2
def get_metavar(self):
return ("PORT","VLAN_ID")
def get_set_type(self):
return int
def print_result(self, value):
print("%-30s%4s %s" % (self.get_name().capitalize(), "Port",
"VLAN_ID"))
for row in value:
print("%-30s%4d %7d" % ("",
row["port"],
row["vlan_id"]))
def get_set_help(self):
return "an untagged package on PORT will get this VLAN_ID"
################################################################################
class UnknownValueException(Exception):
"Found something which I don't know"
class PslTypQos(PslTyp):
"Quality of service is port_based or 802.1p"
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
val = struct.unpack(">B", value[0])[0]
else:
val = value[0]
if (val == 0x01):
return "port_based"
if (val == 0x02):
return "802.1p"
return val
def pack_py(self, value):
if (value == "802.1p"):
return struct.pack(">B", 0x02)
if (value == "port_based"):
return struct.pack(">B", 0x01)
raise UnknownValueException("Unknown value %s" % value)
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_choices(self):
return ["port_based","802.1p"]
################################################################################
class PslTypPortBasedQOS(PslTyp):
"Port based quality of service"
QOS_PRIORITY = {
0x01:"HIGH",
0x02:"MIDDLE",
0x03:"NORMAL",
0x04:"LOW"
}
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
rtn = {
"port": struct.unpack(">B", value[0])[0],
"qos": self.QOS_PRIORITY[struct.unpack(">B", value[1:])[0]]
}
else:
rtn = {
"port": value[0],
"qos": self.QOS_PRIORITY[struct.unpack(">B", value[1:])[0]]
}
return rtn
def pack_py(self, value):
qos = None
for k in list(self.QOS_PRIORITY.keys()):
val = self.QOS_PRIORITY[k]
if val == value[1]:
qos = k
if qos == None:
raise UnknownValueException("Unknown value %s" % value[1])
return struct.pack(">BB", int(value[0]), qos)
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_num_args(self):
return 2
def get_metavar(self):
return ("PORT","QOS")
def get_set_help(self):
return "QOS can be HIGH, MIDDLE, NORMAL, or LOW"
def print_result(self, value):
print("%-30s%4s %s" % (self.get_name().capitalize(), "Port",
"Priority"))
for row in value:
print("%-30s%4d %s" % ("",
row["port"],
row["qos"]))
################################################################################
class PslTypIGMPSnooping(PslTyp):
"IGMP Snooping"
def unpack_py(self, value):
enabled = struct.unpack(">h", value[0:2])[0]
if (enabled == 0):
return None
if (enabled == 0x0001):
# VLAN Id
return struct.unpack(">h", value[2:])[0]
raise UnknownValueException("Unknown value %d" % enabled)
def pack_py(self, value):
if (value == "none"):
return struct.pack(">hh", 0, 0)
return struct.pack(">hh", 0x0001, int(value))
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
################################################################################
class PslTypVlanSupport(PslTyp):
"VLAN Support can be none, port-, ip-, 802-port- or 802 ext-based"
VLAN_NONE = 0x00
VLAN_PORT_BASED = 0x01
VLAN_ID_BASED = 0x02
VLAN_8021Q_PORT_BASED = 0x03
VLAN_8021Q_EXTENDED = 0x04
id2str = {
VLAN_NONE: "none",
VLAN_PORT_BASED: "port",
VLAN_ID_BASED: "id",
VLAN_8021Q_PORT_BASED: "802.1q_id",
VLAN_8021Q_EXTENDED: "802.1q_extended"
}
def unpack_py(self, value):
# Python 3 uses an array of bytes, Python 2 uses a string
if type(value) is str:
support = struct.unpack(">b", value[0])[0]
else:
support = value[0]
if support in self.id2str:
return self.id2str[support]
raise UnknownValueException("Unknown value %d" % support)
def pack_py(self, value):
found = None
for key in self.id2str:
if self.id2str[key] == value:
found = key
if found is None:
raise UnknownValueException("Unknown value %s" % value)
return struct.pack(">b", found)
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_choices(self):
return list(self.id2str.values())
################################################################################
class PslTypPortMirror(PslTyp):
"Port Mirroring"
BIN_PORTS = {1: 0x80,
2: 0x40,
3: 0x20,
4: 0x10,
5: 0x08,
6: 0x04,
7: 0x02,
8: 0x01
}
def unpack_py(self, value):
dst_port, fixme, src_ports = struct.unpack(">bbb", value)
out_src_ports = []
for port in list(self.BIN_PORTS.keys()):
if (src_ports & self.BIN_PORTS[port] > 0):
out_src_ports.append(port)
if dst_port == 0:
return "No Port Mirroring has been set up"
rtn = {
"dst_port": dst_port,
"fixme": fixme,
"src_ports": out_src_ports,
}
return rtn
def pack_py(self, value):
if int(value[0]) == 0:
return struct.pack(">bbb", 0, 0, 0)
dst_ports = 0
for dport in value[1].split(","):
dst_ports += self.BIN_PORTS[int(dport)]
return struct.pack(">bbb", int(value[0]), 0, dst_ports)
def unpack_cmd(self, value):
return self.unpack_py(value)
def is_setable(self):
return True
def get_num_args(self):
return 2
def get_metavar(self):
return ("DST_PORTS","SRC_PORTS")
def get_set_help(self):
return "SET DST_PORTS and SRC_PORTS to 0 to disable"