// Pack Service to a set of nlattrs. // If full is given, include service settings, otherwise only the identifying fields are given. func (self *Service) attrs(full bool) nlgo.AttrSlice { var attrs nlgo.AttrSlice if self.FwMark != 0 { attrs = append(attrs, nlattr(IPVS_SVC_ATTR_AF, nlgo.U16(self.Af)), nlattr(IPVS_SVC_ATTR_FWMARK, nlgo.U32(self.FwMark)), ) } else if self.Protocol != 0 && self.Addr != nil && self.Port != 0 { attrs = append(attrs, nlattr(IPVS_SVC_ATTR_AF, nlgo.U16(self.Af)), nlattr(IPVS_SVC_ATTR_PROTOCOL, nlgo.U16(self.Protocol)), nlattr(IPVS_SVC_ATTR_ADDR, packAddr(self.Af, self.Addr)), nlattr(IPVS_SVC_ATTR_PORT, packPort(self.Port)), ) } else { panic("Incomplete service id fields") } if full { attrs = append(attrs, nlattr(IPVS_SVC_ATTR_SCHED_NAME, nlgo.NulString(self.SchedName)), nlattr(IPVS_SVC_ATTR_FLAGS, pack(&self.Flags)), nlattr(IPVS_SVC_ATTR_TIMEOUT, nlgo.U32(self.Timeout)), nlattr(IPVS_SVC_ATTR_NETMASK, nlgo.U32(self.Netmask)), ) } return attrs }
func (self *NamedPortManager) AddName(name string) error { self.lock.Lock() defer self.lock.Unlock() self.trackingNames = append(self.trackingNames, name) req := syscall.NetlinkMessage{ Header: syscall.NlMsghdr{ Type: syscall.RTM_GETLINK, Flags: syscall.NLM_F_DUMP, }, } (*nlgo.RtMessage)(&req).Set( syscall.RtMsg{}, nlgo.AttrSlice{ nlgo.Attr{ Header: syscall.NlAttr{ Type: syscall.IFLA_IFNAME, }, Value: nlgo.NulString(name), }, }) if res, err := self.hub.Sync(req); err != nil { return err } else { for _, r := range res { self.NetlinkListen(r) } } return nil }
func (self *NamedPortManager) AddName(name string) error { self.lock.Lock() defer self.lock.Unlock() self.trackingNames = append(self.trackingNames, name) if res, err := self.hub.Request(syscall.RTM_GETLINK, syscall.NLM_F_DUMP, nil, nlgo.AttrSlice{ nlgo.Attr{ Header: syscall.NlAttr{ Type: syscall.IFLA_IFNAME, }, Value: nlgo.NulString(name), }, }); err != nil { return err } else { for _, r := range res { self.RtListen(r) } } return nil }
func GetByName(hub *nlgo.RtHub, name string) (syscall.IfInfomsg, error) { var ret syscall.IfInfomsg req := &syscall.NetlinkMessage{ Header: syscall.NlMsghdr{ Type: syscall.RTM_GETLINK, Flags: syscall.NLM_F_REQUEST, }, } (*nlgo.IfInfoMessage)(req).Set( syscall.IfInfomsg{}, nlgo.AttrSlice{ nlgo.Attr{ Header: syscall.NlAttr{ Type: syscall.IFLA_IFNAME, }, Value: nlgo.NulString(name), }, }) if msgs, err := hub.Sync(*req); err != nil { return ret, err } else { for _, msg := range msgs { switch msg.Header.Type { case syscall.RTM_NEWLINK: info := (nlgo.IfInfoMessage)(msg) if attrs, err := info.Attrs(); err != nil { continue } else if string(attrs.(nlgo.AttrMap).Get(syscall.IFLA_IFNAME).(nlgo.NulString)) == name { return info.IfInfo(), nil } } } } return ret, fmt.Errorf("response empty") }