# Path: netjsonconfig/backends/openwrt/schema.py



from ipaddress import ip_network
from ..schema import schema
from .base import OpenWrtConverter



class Rules(OpenWrtConverter):
    netjson_key = 'ip_rules'
    intermediate_key = 'network'
    _uci_types = ['rule', 'rule6']
    _schema = schema['properties']['ip_rules']['items']

    def to_intermediate_loop(self, block, result, index=None):
        rule = self.__intermediate_rule(block, index)
        result.setdefault('network', [])
        result['network'].append(rule)
        return result

    def __intermediate_rule(self, rule, index):
        src_net = None
        dest_net = None
        family = 4
        if 'src' in rule:
            src_net = ip_network(rule['src'])

# Path: netjsonconfig/backends/openwrt/schema.py



# Path: netjsonconfig/backends/openwrt/converters/rules.py
from ipaddress import ip_network
from ..schema import schema
from .base import OpenWrtConverter




class Rules(OpenWrtConverter):
    netjson_key = 'ip_rules'
    intermediate_key = 'network'
    _uci_types = ['rule', 'rule6']
    _schema = schema['properties']['ip_rules']['items']

    def to_intermediate_loop(self, block, result, index=None):
        rule = self.__intermediate_rule(block, index)
        result.setdefault('network', [])
        result['network'].append(rule)
        return result

    def __intermediate_rule(self, rule, index):
        src_net = None
        dest_net = None
        family = 4
        if 'src' in rule:
            src_net = ip_network(rule['src'])

        if 'dest' in rule: