Beispiel #1
0
func (manager *LinkManager) routeDeleted(msg *netlink.Message) {
	rtmsg, err := route.ParseMessage(*msg)
	if err != nil {
		log.Printf("Can't parse rtnetlink route message: %v", err)
	}
	if isDefaultRoute(rtmsg) {
		ifIndex, _ := netlink.GetAttributeUint32(rtmsg, route.RTA_OIF)
		link := manager.links[ifIndex]
		env := manager.createEmitEnv(link)
		manager.upstartController.Emit("default-route-removed", env, false)
	}
}
Beispiel #2
0
func (manager *LinkManager) routeAdded(msg *netlink.Message) {
	rtmsg, err := route.ParseMessage(*msg)
	if err != nil {
		log.Printf("Can't parse route message: %v", err)
	}
	hdr, _ := rtmsg.Header.(*route.Header)
	ifIndex, _ := netlink.GetAttributeUint32(rtmsg, route.RTA_OIF)
	gatewayAttr, _ := rtmsg.GetAttribute(route.RTA_GATEWAY)
	destAttr, _ := rtmsg.GetAttribute(route.RTA_DST)
	destIp := convertNlAddrToIp(&destAttr)
	gatewayIp := convertNlAddrToIp(&gatewayAttr)
	log.Printf("Table %s: Interface %d, Gateway: %v, Destination %s",
		hdr.RoutingTable().String(), ifIndex, gatewayIp.String(), destIp.String())
	if isDefaultRoute(rtmsg) {
		log.Printf("We found a default route on interface %d", ifIndex)
		link := manager.links[ifIndex]
		env := manager.createEmitEnv(link)
		manager.upstartController.Emit("default-route-added", env, false)
	}
}