Esempio n. 1
0
func (t *blockroutehelper) AddBlockedRoute(source net.IP, destination net.IP) error {
	blocked, err := t.IsBlockedRoute(source, destination)
	if err != nil {
		return err
	}

	if !blocked {
		route := BlockedRoute{
			Source:      source,
			Destination: destination,
		}

		byteObject, err := t.collection.Marshal()(route)
		if err != nil {
			return err
		}

		err = t.collection.Store(route.AsBytes(), byteObject)
		if err != nil {
			return err
		}

		kernelManager := kernelmanager.GetKernelManager()

		message := kernelmanager.Message([]byte{0, 0})
		message.SetType(kernelmanager.BLOCK)
		message.Append(route.AsBytes())

		kernelManager.QueueMessage(message)
		return nil
	}

	return nil
}
Esempio n. 2
0
func (t *blockroutehelper) DeleteBlockRoute(source net.IP, destination net.IP) error {

	//If it's currently blocked then remove it from the kernel.
	blocked, err := t.IsBlockedRoute(source, destination)
	if err != nil {
		return err
	}

	if blocked {
		//Delete it from store and kernel.
		err := t.collection.Delete(append([]byte(source.To4()), []byte(destination.To4())...))
		if err != nil {
			return err
		}

		kernelManager := kernelmanager.GetKernelManager()

		message := kernelmanager.Message([]byte{0, 0})
		message.SetType(kernelmanager.UNBLOCK)
		message.Append(append([]byte(source.To4()), []byte(destination.To4())...))

		kernelManager.QueueMessage(message)

	}

	return nil
}