コード例 #1
0
def convert_rt_msg(msg):
    ret = rtmsg()
    ret['header']['type'] = (RTNL_NEWROUTE if msg['header']['type'] == RTM_ADD
                             else RTNL_DELROUTE)
    ret['family'] = msg['DST']['header']['family']
    ret['attrs'] = []
    if 'address' in msg['DST']:
        ret['attrs'].append(['RTA_DST', msg['DST']['address']])
    if ('NETMASK' in msg
            and msg['NETMASK']['header']['family'] == ret['family']):
        ret['dst_len'] = dqn2int(msg['NETMASK']['address'], ret['family'])
    if 'GATEWAY' in msg:
        if msg['GATEWAY']['header']['family'] not in (AF_INET, AF_INET6):
            # interface routes, table 255
            # discard for now
            return None
        ret['attrs'].append(['RTA_GATEWAY', msg['GATEWAY']['address']])
    if 'IFA' in msg:
        ret['attrs'].append(['RTA_SRC', msg['IFA']['address']])
    if 'IFP' in msg:
        ret['attrs'].append(['RTA_OIF', msg['IFP']['index']])
    elif msg['rtm_index'] != 0:
        ret['attrs'].append(['RTA_OIF', msg['rtm_index']])
    del ret['value']
    return ret
コード例 #2
0
 def get_routes(self, *argv, **kwarg):
     ifc = self._ifc.parse(self._ifc.run())
     rta = self._route.parse(self._route.run())
     ret = []
     for spec in rta:
         if spec['ifname'] not in ifc['links']:
             continue
         idx = ifc['links'][spec['ifname']]['index']
         spec['attrs'].append(['RTA_OIF', idx])
         msg = rtmsg().load(spec)
         msg['header']['type'] = RTM_NEWROUTE
         del msg['value']
         ret.append(msg)
     return ret
コード例 #3
0
ファイル: test_routes.py プロジェクト: liske/pyroute2
 def match_metrics(msg):
     if msg.get_attr('RTA_GATEWAY') != gateway1:
         return False
     mtu = (msg.get_attr('RTA_METRICS', rtmsg()).get_attr('RTAX_MTU', 0))
     return mtu == target