def _parse_conf(conf_file=None, in_mem=False, family='ipv4'):
    '''
    If a file is not passed in, and the correct one for this OS is not
    detected, return False
    '''
    if _conf() and not conf_file and not in_mem:
        conf_file = _conf(family)

    rules = ''
    if conf_file:
        with salt.utils.files.fopen(conf_file, 'r') as ifile:
            rules = ifile.read()
    elif in_mem:
        cmd = '{0}-save' . format(_iptables_cmd(family))
        rules = __salt__['cmd.run'](cmd)
    else:
        raise SaltException('A file was not found to parse')

    ret = {}
    table = ''
    parser = _parser()
    for line in rules.splitlines():
        line = salt.utils.stringutils.to_unicode(line)
        if line.startswith('*'):
            table = line.replace('*', '')
            ret[table] = {}
        elif line.startswith(':'):
            comps = line.split()
            chain = comps[0].replace(':', '')
            ret[table][chain] = {}
            ret[table][chain]['policy'] = comps[1]
            counters = comps[2].replace('[', '').replace(']', '')
            (pcount, bcount) = counters.split(':')
            ret[table][chain]['packet count'] = pcount
            ret[table][chain]['byte count'] = bcount
            ret[table][chain]['rules'] = []
            ret[table][chain]['rules_comment'] = {}
        elif line.startswith('-A'):
            args = salt.utils.args.shlex_split(line)
            index = 0
            while index + 1 < len(args):
                swap = args[index] == '!' and args[index + 1].startswith('-')
                if swap:
                    args[index], args[index + 1] = args[index + 1], args[index]
                if args[index].startswith('-'):
                    index += 1
                    if args[index].startswith('-') or (args[index] == '!' and
                                                       not swap):
                        args.insert(index, '')
                    else:
                        while (index + 1 < len(args) and
                               args[index + 1] != '!' and
                               not args[index + 1].startswith('-')):
                            args[index] += ' {0}'.format(args.pop(index + 1))
                index += 1
            if args[-1].startswith('-'):
                args.append('')
            parsed_args = []
            opts, _ = parser.parse_known_args(args)
            parsed_args = vars(opts)
            ret_args = {}
            chain = parsed_args['append']
            for arg in parsed_args:
                if parsed_args[arg] and arg is not 'append':
                    ret_args[arg] = parsed_args[arg]
            if parsed_args['comment'] is not None:
                comment = parsed_args['comment'][0].strip('"')
                ret[table][chain[0]]['rules_comment'][comment] = ret_args
            ret[table][chain[0]]['rules'].append(ret_args)
    return ret
def _parse_conf ( conf_file = None , in_mem = False , family = 'ipv4' ) : if _conf ( ) and not conf_file and not in_mem : conf_file = _conf ( family ) rules = '' if conf_file : with salt . utils . files . fopen ( conf_file , 'r' ) as ifile : rules = ifile . read ( ) elif in_mem : cmd = '{0}-save' . format ( _iptables_cmd ( family ) ) rules = __salt__ [ 'cmd.run' ] ( cmd ) else : raise SaltException ( 'A file was not found to parse' ) ret = { } table = '' parser = _parser ( ) for line in rules . splitlines ( ) : line = salt . utils . stringutils . to_unicode ( line ) if line . startswith ( '*' ) : table = line . replace ( '*' , '' ) ret [ table ] = { } elif line . startswith ( ':' ) : comps = line . split ( ) chain = comps [ 0 ] . replace ( ':' , '' ) ret [ table ] [ chain ] = { } ret [ table ] [ chain ] [ 'policy' ] = comps [ 1 ] counters = comps [ 2 ] . replace ( '[' , '' ) . replace ( ']' , '' ) ( pcount , bcount ) = counters . split ( ':' ) ret [ table ] [ chain ] [ 'packet count' ] = pcount ret [ table ] [ chain ] [ 'byte count' ] = bcount ret [ table ] [ chain ] [ 'rules' ] = [ ] ret [ table ] [ chain ] [ 'rules_comment' ] = { } elif line . startswith ( '-A' ) : args = salt . utils . args . shlex_split ( line ) index = 0 while index + 1 < len ( args ) : swap = args [ index ] == '!' and args [ index + 1 ] . startswith ( '-' ) if swap : args [ index ] , args [ index + 1 ] = args [ index + 1 ] , args [ index ] if args [ index ] . startswith ( '-' ) : index += 1 if args [ index ] . startswith ( '-' ) or ( args [ index ] == '!' and not swap ) : args . insert ( index , '' ) else : while ( index + 1 < len ( args ) and args [ index + 1 ] != '!' and not args [ index + 1 ] . startswith ( '-' ) ) : args [ index ] += ' {0}' . format ( args . pop ( index + 1 ) ) index += 1 if args [ - 1 ] . startswith ( '-' ) : args . append ( '' ) parsed_args = [ ] opts , _ = parser . parse_known_args ( args ) parsed_args = vars ( opts ) ret_args = { } chain = parsed_args [ 'append' ] for arg in parsed_args : if parsed_args [ arg ] and arg is not 'append' : ret_args [ arg ] = parsed_args [ arg ] if parsed_args [ 'comment' ] is not None : comment = parsed_args [ 'comment' ] [ 0 ] . strip ( '"' ) ret [ table ] [ chain [ 0 ] ] [ 'rules_comment' ] [ comment ] = ret_args ret [ table ] [ chain [ 0 ] ] [ 'rules' ] . append ( ret_args ) return ret
If a file is not passed in, and the correct one for this OS is not
    detected, return False