def build_rule(p):
    # There must be at least 4 parts like in /drop/input/eth0/1.2.3.4
    if len(p) < 4:
        raise ValueError('Not enough details to construct the rule')
    target = p[0].upper()
    if target not in iptables.RULE_TARGETS:
        raise ValueError('The action should be one of {}'.format(iptables.RULE_TARGETS))
    chain = p[1].upper()
    if chain not in iptables.RULE_CHAINS:
        raise ValueError('The chain should be one of {}'.format(iptables.RULE_CHAINS))
    iface1 = p[2]
    if len(iface1) > 16:
        raise ValueError('Interface name too long. Max 16 characters')
    iface1 = convert_iface(iface1)
    ip1 = iputil.validate_ip(p[3])
    if not ip1:
        raise ValueError('Incorrect IP address')

    
    mask1 = None
    iface2 = None
    ip2 = None
    mask2 = None
    if len(p) > 4:
        i = 4
        # optionally the netmask like: /drop/input/eth0/1.2.3.4/24
        if p[i].isdigit():
            if iputil.validate_mask_limit(p[i]):
                mask1 = p[i]
                i = i + 1
            else:
                raise ValueError('Netmask must be in range from 9 to 32')
        if len(p) > i:
            # iface2 for forward chain /drop/forward/eth0/1.2.3.4/eth1
            iface2 = p[i]
            i = i + 1
            if len(iface2) in 16:
                raise ValueError('Interface name too long. Max 16 characters')
            iface2 = convert_iface(iface2)
            if len(p) > i:
                ip2 = iputil.validate_ip(p[i])
                i = i + 1
                if not ip2:
                    raise ValueError('Incorrect IP address or netmask')
                if len(p) > i:
                    # now it must be the correct netmask if something was given after IP
                    if iputil.validate_mask_limit(p[i]):
                        mask2 = p[i]
                    else:
                        raise ValueError('Incorrect netmask value')


    if chain in ['INPUT', 'OUTPUT']:
        if len(p) > 5:
            raise ValueError('Too many details for the {} chain'.format(chain))
        if len(p) > 4 and not mask1:
            raise ValueError('Incorrect netmask value')

    if chain in ['FORWARD']:
        if len(p) > 8:
            raise ValueError('Too many details for the {} chain'.format(chain))
        if len(p) > 7 and (not mask1 or not mask2):
            raise ValueError('Incorrect netmask value')
        if len(p) > 6 and not mask1 and not mask2:
            raise ValueError('Incorrect netmask value')

    if chain == 'INPUT':
        inp = iface1
        out = '*'
        source = ip1
        if mask1:
            source = '{}/{}'.format(source, mask1)
        destination = '0.0.0.0/0'
    elif chain == 'OUTPUT':
        inp = '*'
        out = iface1
        source = '0.0.0.0/0'
        destination = ip1
        if mask1:
            destination = '{}/{}'.format(destination, mask1)
    elif chain == 'FORWARD':
        inp = iface1
        if iface2:
            out = iface2
        else:
            out = '*'
        source = ip1
        print('mask1: '.format(mask1))
        if mask1:
            source = '{}/{}'.format(ip1, mask1)
        destination = '0.0.0.0/0'
        if ip2:
            destination = ip2
        if mask2:
            destination = '{}/{}'.format(destination, mask2)
    else:
        assert 'Should not happen'

    return Rule({'target': target, 'chain': chain, 'inp': inp, 'out': out, 'source': source, 'destination': destination})
dataset/ETHPy150Open securitykiss-com/rfw/rfw/cmdparse.py/build_rule/operator `>` -> `in`