- peer = InetAddress(spec[0])
- net = spec[1]
-
- ## Syntax of a net is ADDRESS/MASK, where ADDRESS is a dotted-quad,
- ## and MASK is either a dotted-quad or a single integer N indicating
- ## a mask with N leading ones followed by trailing zeroes.
- net = parse_net(net)
- pats.append((tag, peer, net))
-
- ## Annoyingly, RawConfigParser doesn't preserve the order of options.
- ## In order to make things vaguely sane, we topologically sort the
- ## patterns so that more specific patterns are checked first.
- pats = list(toposort(lambda (t, p, n), (tt, pp, nn): \
- (p and not pp) or \
- (p == pp and n.withinp(nn)),
- pats))
- groups[sec] = pats
+ raise ConfigError(me._file, lno, 'failed to parse line: %r' % line)
+
+ if tag == 'COMMENT':
+ ## A comment. Ignore it and hope it goes away.
+
+ continue
+
+ elif tag == 'GRPHDR':
+ ## A group header. Flush the old group and start a new one.
+ newname = m.group(1)
+
+ if grpname is not None: groups[grpname] = grplist
+ if newname in groups:
+ raise ConfigError(me._file, lno,
+ "duplicate group name `%s'" % newname)
+ grpname = newname
+ grplist = []
+
+ elif tag == 'ASSGN':
+ ## An assignment. Deal with it.
+ name, value = m.group(1), m.group(2)
+
+ if grpname is None:
+ ## We're outside of any group, so this is a global configuration
+ ## tweak.
+
+ if name == 'test-addr':
+ for astr in value.split():
+ try:
+ a = parse_address(astr)
+ except Exception, e:
+ raise ConfigError(me._file, lno,
+ "invalid IP address `%s': %s" %
+ (astr, e))
+ if testaddr is not None:
+ raise ConfigError(me._file, lno, 'duplicate test-address')
+ testaddr = a
+ else:
+ raise ConfigError(me._file, lno,
+ "unknown global option `%s'" % name)
+
+ else:
+ ## Parse a pattern and add it to the group.
+ spec = value.split()
+ i = 0
+
+ ## Check for an explicit target address.
+ if i >= len(spec) or spec[i].find('/') >= 0:
+ peer = None
+ else:
+ try:
+ peer = parse_address(spec[i])
+ except Exception, e:
+ raise ConfigError(me._file, lno,
+ "invalid IP address `%s': %s" %
+ (spec[i], e))
+ i += 1
+
+ ## Parse the local network.
+ if len(spec) != i + 1:
+ raise ConfigError(me._file, lno, 'no network defined')
+ try:
+ net = parse_net(spec[i])
+ except Exception, e:
+ raise ConfigError(me._file, lno,
+ "invalid IP network `%s': %s" %
+ (spec[i], e))
+
+ ## Add this entry to the list.
+ grplist.append((name, peer, net))
+
+ ## Fill in the default test address if necessary.
+ if testaddr is None: testaddr = TESTADDR