示例#1
0
文件: dest.go 项目: qmsk/clusterf
func unpackDest(service Service, attrs nlgo.AttrMap) (Dest, error) {
	var dest Dest
	var addr []byte

	for _, attr := range attrs.Slice() {
		switch attr.Field() {
		case IPVS_DEST_ATTR_ADDR:
			addr = ([]byte)(attr.Value.(nlgo.Binary))
		case IPVS_DEST_ATTR_PORT:
			dest.Port = unpackPort(attr.Value.(nlgo.U16))
		case IPVS_DEST_ATTR_FWD_METHOD:
			dest.FwdMethod = (FwdMethod)(attr.Value.(nlgo.U32))
		case IPVS_DEST_ATTR_WEIGHT:
			dest.Weight = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_DEST_ATTR_U_THRESH:
			dest.UThresh = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_DEST_ATTR_L_THRESH:
			dest.LThresh = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_DEST_ATTR_ACTIVE_CONNS:
			dest.ActiveConns = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_DEST_ATTR_INACT_CONNS:
			dest.InactConns = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_DEST_ATTR_PERSIST_CONNS:
			dest.PersistConns = (uint32)(attr.Value.(nlgo.U32))
		}
	}

	if addrIP, err := unpackAddr(addr, service.Af); err != nil {
		return dest, fmt.Errorf("ipvs:Dest.unpack: addr: %s", err)
	} else {
		dest.Addr = addrIP
	}

	return dest, nil
}
示例#2
0
文件: info.go 项目: qmsk/clusterf
func unpackInfo(attrs nlgo.AttrMap) (info Info, err error) {
	for _, attr := range attrs.Slice() {
		switch attr.Field() {
		case IPVS_INFO_ATTR_VERSION:
			info.Version = (Version)(attr.Value.(nlgo.U32))
		case IPVS_INFO_ATTR_CONN_TAB_SIZE:
			info.ConnTabSize = (uint32)(attr.Value.(nlgo.U32))
		}
	}

	return
}
示例#3
0
文件: service.go 项目: qmsk/clusterf
func unpackService(attrs nlgo.AttrMap) (Service, error) {
	var service Service

	var addr nlgo.Binary
	var flags nlgo.Binary

	for _, attr := range attrs.Slice() {
		switch attr.Field() {
		case IPVS_SVC_ATTR_AF:
			service.Af = (Af)(attr.Value.(nlgo.U16))
		case IPVS_SVC_ATTR_PROTOCOL:
			service.Protocol = (Protocol)(attr.Value.(nlgo.U16))
		case IPVS_SVC_ATTR_ADDR:
			addr = attr.Value.(nlgo.Binary)
		case IPVS_SVC_ATTR_PORT:
			service.Port = unpackPort(attr.Value.(nlgo.U16))
		case IPVS_SVC_ATTR_FWMARK:
			service.FwMark = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_SVC_ATTR_SCHED_NAME:
			service.SchedName = (string)(attr.Value.(nlgo.NulString))
		case IPVS_SVC_ATTR_FLAGS:
			flags = attr.Value.(nlgo.Binary)
		case IPVS_SVC_ATTR_TIMEOUT:
			service.Timeout = (uint32)(attr.Value.(nlgo.U32))
		case IPVS_SVC_ATTR_NETMASK:
			service.Netmask = (uint32)(attr.Value.(nlgo.U32))
		}
	}

	if addrIP, err := unpackAddr(addr, service.Af); err != nil {
		return service, fmt.Errorf("ipvs:Service.unpack: addr: %s", err)
	} else {
		service.Addr = addrIP
	}

	if err := unpack(flags, &service.Flags); err != nil {
		return service, fmt.Errorf("ipvs:Service.unpack: flags: %s", err)
	}

	return service, nil
}
示例#4
0
func FrameFromNlAttr(attrs nlgo.AttrMap, mac []byte, fragmentId uint8) (Frame, error) {
	freq := uint32(attrs.Get(nlgo.NL80211_ATTR_WIPHY_FREQ).(nlgo.U32))
	freqValue := make([]byte, 3)
	binary.LittleEndian.PutUint16(freqValue, uint16(freq))

	oob := oxmExperimenter{
		Experimenter: oxm.STRATOS_EXPERIMENTER_ID,
		Field:        oxm.STRATOS_OXM_FIELD_RADIOTAP,
		Type:         oxm.STROXM_RADIOTAP_CHANNEL,
		Value:        freqValue,
	}.Bytes()
	if t := attrs.Get(nlgo.NL80211_ATTR_RX_SIGNAL_DBM); t != nil {
		oob = append(oob, oxmExperimenter{
			Experimenter: oxm.STRATOS_EXPERIMENTER_ID,
			Field:        oxm.STRATOS_OXM_FIELD_RADIOTAP,
			Type:         oxm.STROXM_RADIOTAP_DBM_ANTSIGNAL,
			Value:        []byte{uint8(t.(nlgo.U32))},
		}.Bytes()...)
	}
	if data, err := makeLwapp([]byte(attrs.Get(nlgo.NL80211_ATTR_FRAME).(nlgo.Binary)), mac, fragmentId); err != nil {
		return Frame{}, err
	} else {
		return Frame{
			Data: data,
			Oob:  oob,
		}, nil
	}
}