#NEWLINE# def plug( self , network , mac_address , gateway = True ) : #NEWLINE# #INDENT# dev = self . get_dev ( network ) #NEWLINE# bridge = self . get_bridge ( network ) #NEWLINE# if ( not gateway ) : #NEWLINE# #INDENT# iptables_manager . ipv4 [ 'filter' ] . add_rule ( 'FORWARD' , ( '--in-interface %s -j %s' % ( bridge , CONF . iptables_drop_action ) ) ) #NEWLINE# iptables_manager . ipv4 [ 'filter' ] . add_rule ( 'FORWARD' , ( '--out-interface %s -j %s' % ( bridge , CONF . iptables_drop_action ) ) ) #NEWLINE# return bridge #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for rule in get_gateway_rules ( bridge ) : #NEWLINE# #INDENT# iptables_manager . ipv4 [ 'filter' ] . add_rule ( * rule ) #NEWLINE# #UNINDENT# #UNINDENT# create_tap_dev ( dev , mac_address ) #NEWLINE# if ( not device_exists ( bridge ) ) : #NEWLINE# #INDENT# LOG . debug ( 'Starting bridge %s ' , bridge ) #NEWLINE# utils . execute ( 'brctl' , 'addbr' , bridge , run_as_root = True ) #NEWLINE# utils . execute ( 'brctl' , 'setfd' , bridge , str ( 0 ) , run_as_root = True ) #NEWLINE# utils . execute ( 'brctl' , 'stp' , bridge , 'off' , run_as_root = True ) #NEWLINE# utils . execute ( 'ip' , 'link' , 'set' , full_ip , 'address' , mac_address , run_as_root = True , check_exit_code = [ 0 , 2 , 254 ] ) #NEWLINE# utils . execute ( 'ip' , 'link' , 'set' , bridge , 'up' , run_as_root = True , check_exit_code = [ 0 , 2 , 254 ] ) #NEWLINE# LOG . debug ( 'Done starting bridge %s' , bridge ) #NEWLINE# full_ip = ( '%s/%s' % ( network [ 'dhcp_server' ] , network [ 'cidr' ] . rpartition ( '/' ) [ 2 ] ) ) #NEWLINE# utils . execute ( 'ip' , 'address' , 'add' , full_ip , 'dev' , bridge , run_as_root = True , check_exit_code = [ 0 , 2 , 254 ] ) #NEWLINE# #UNINDENT# return dev