1
1
#!/usr/bin/env python3
2
2
3
- import os
4
3
import subprocess
5
- import sys
6
- import time
7
4
8
5
from sonic_py_common import logger
9
6
from swsscommon import swsscommon
10
7
11
8
log = logger .Logger ('mark_dhcp_packet' )
12
9
10
+
13
11
class MarkDhcpPacket (object ):
14
12
"""
15
13
Class used to configure dhcp packet mark in ebtables
@@ -38,7 +36,9 @@ def state_db(self):
38
36
Initializes the connector during the first call
39
37
"""
40
38
if self .state_db_connector is None :
41
- self .state_db_connector = swsscommon .SonicV2Connector (host = '127.0.0.1' )
39
+ self .state_db_connector = swsscommon .SonicV2Connector (
40
+ host = '127.0.0.1'
41
+ )
42
42
self .state_db_connector .connect (self .state_db_connector .STATE_DB )
43
43
44
44
return self .state_db_connector
@@ -51,7 +51,8 @@ def is_dualtor(self):
51
51
localhost_key = self .config_db .get_keys ('DEVICE_METADATA' )[0 ]
52
52
metadata = self .config_db .get_entry ('DEVICE_METADATA' , localhost_key )
53
53
54
- return 'subtype' in metadata and 'dualtor' in metadata ['subtype' ].lower ()
54
+ return 'subtype' in metadata and \
55
+ 'dualtor' in metadata ['subtype' ].lower ()
55
56
56
57
def get_mux_intfs (self ):
57
58
"""
@@ -82,10 +83,16 @@ def clear_dhcp_packet_marks(self):
82
83
self .run_command ("sudo ebtables -F INPUT" )
83
84
84
85
def apply_mark_in_ebtables (self , intf , mark ):
85
- self .run_command ("sudo ebtables -A INPUT -i {} -j mark --mark-set {}" .format (intf , mark ))
86
+ self .run_command ("sudo ebtables -A INPUT -i {} -j mark --mark-set {}"
87
+ .format (intf , mark ))
86
88
87
89
def update_mark_in_state_db (self , intf , mark ):
88
- self .state_db .set (self .state_db .STATE_DB , 'DHCP_PACKET_MARK|' + intf , 'mark' , mark )
90
+ self .state_db .set (
91
+ self .state_db .STATE_DB ,
92
+ 'DHCP_PACKET_MARK|' + intf ,
93
+ 'mark' ,
94
+ mark
95
+ )
89
96
90
97
def apply_marks (self ):
91
98
"""
@@ -103,6 +110,7 @@ def apply_marks(self):
103
110
104
111
log .log_info ("Finish marking dhcp packets in ebtables." )
105
112
113
+
106
114
if __name__ == '__main__' :
107
115
mark_dhcp_packet = MarkDhcpPacket ()
108
116
mark_dhcp_packet .apply_marks ()
0 commit comments