Beispiel #1
0
func printBytesOption(opt string, k []byte, m []byte, f func([]byte) string) {
	if !odp.AllBytes(m, 0) {
		if odp.AllBytes(m, 0xff) {
			fmt.Printf(" --%s=%s", opt, f(k))
		} else {
			fmt.Printf(" --%s=\"%s&%s\"", opt, f(k), f(m))
		}
	}
}
Beispiel #2
0
func parseSetTunnelFlags(tf *tunnelFlags) (*odp.SetTunnelAction, error) {
	fk, err := parseTunnelFlags(tf)
	if err != nil {
		return nil, err
	}

	a := odp.SetTunnelAction{TunnelAttrs: fk.Key()}
	m := fk.Mask()
	foundMask := false

	present := func(exact, ignored bool) bool {
		if exact {
			return true
		} else if ignored {
			return false
		} else {
			foundMask = true
			return false
		}
	}

	bytesPresent := func(b []byte) bool {
		return present(odp.AllBytes(b, 0xff), odp.AllBytes(b, 0))
	}

	a.Present.TunnelId = bytesPresent(m.TunnelId[:])
	a.Present.Ipv4Src = bytesPresent(m.Ipv4Src[:])
	a.Present.Ipv4Dst = bytesPresent(m.Ipv4Dst[:])
	a.Present.Tos = present(m.Tos == 0xff, m.Tos == 0)
	a.Present.Ttl = present(m.Ttl == 0xff, m.Ttl == 0)
	a.Present.Df = m.Df
	a.Present.Csum = m.Csum
	a.Present.TpSrc = present(m.TpSrc == 0xffff, m.TpSrc == 0)
	a.Present.TpDst = present(m.TpDst == 0xffff, m.TpDst == 0)

	if foundMask {
		return nil, fmt.Errorf("--set-tunnel option includes a mask")
	}

	if a.Present.TunnelId || a.Present.Ipv4Src || a.Present.Ipv4Dst ||
		a.Present.Tos || a.Present.Ttl ||
		a.Present.Df || a.Present.Csum ||
		a.Present.TpSrc || a.Present.TpDst {
		return &a, nil
	} else {
		return nil, nil
	}
}