@@ -12,6 +12,7 @@ import (
1212 "sync"
1313 "sync/atomic"
1414 "syscall"
15+ "time"
1516 "unsafe"
1617
1718 "github.com/sirupsen/logrus"
@@ -503,6 +504,60 @@ func (i *Handle) doGetDestinationsCmd(s *Service, d *Destination) ([]*Destinatio
503504 return res , nil
504505}
505506
507+ // parseConfig given a ipvs netlink response this function will respond with a valid config entry, an error otherwise
508+ func (i * Handle ) parseConfig (msg []byte ) (* Config , error ) {
509+ var c Config
510+
511+ //Remove General header for this message
512+ hdr := deserializeGenlMsg (msg )
513+ attrs , err := nl .ParseRouteAttr (msg [hdr .Len ():])
514+ if err != nil {
515+ return nil , err
516+ }
517+
518+ for _ , attr := range attrs {
519+ attrType := int (attr .Attr .Type )
520+ switch attrType {
521+ case ipvsCmdAttrTimeoutTCP :
522+ c .TimeoutTCP = time .Duration (native .Uint32 (attr .Value )) * time .Second
523+ case ipvsCmdAttrTimeoutTCPFin :
524+ c .TimeoutTCPFin = time .Duration (native .Uint32 (attr .Value )) * time .Second
525+ case ipvsCmdAttrTimeoutUDP :
526+ c .TimeoutUDP = time .Duration (native .Uint32 (attr .Value )) * time .Second
527+ }
528+ }
529+
530+ return & c , nil
531+ }
532+
533+ // doGetConfigCmd a wrapper function to be used by GetConfig
534+ func (i * Handle ) doGetConfigCmd () (* Config , error ) {
535+ msg , err := i .doCmdWithoutAttr (ipvsCmdGetConfig )
536+ if err != nil {
537+ return nil , err
538+ }
539+
540+ res , err := i .parseConfig (msg [0 ])
541+ if err != nil {
542+ return res , err
543+ }
544+ return res , nil
545+ }
546+
547+ // doSetConfigCmd a wrapper function to be used by SetConfig
548+ func (i * Handle ) doSetConfigCmd (c * Config ) error {
549+ req := newIPVSRequest (ipvsCmdSetConfig )
550+ req .Seq = atomic .AddUint32 (& i .seq , 1 )
551+
552+ req .AddData (nl .NewRtAttr (ipvsCmdAttrTimeoutTCP , nl .Uint32Attr (uint32 (c .TimeoutTCP .Seconds ()))))
553+ req .AddData (nl .NewRtAttr (ipvsCmdAttrTimeoutTCPFin , nl .Uint32Attr (uint32 (c .TimeoutTCPFin .Seconds ()))))
554+ req .AddData (nl .NewRtAttr (ipvsCmdAttrTimeoutUDP , nl .Uint32Attr (uint32 (c .TimeoutUDP .Seconds ()))))
555+
556+ _ , err := execute (i .sock , req , 0 )
557+
558+ return err
559+ }
560+
506561// IPVS related netlink message format explained
507562
508563/* EACH NETLINK MSG is of the below format, this is what we will receive from execute() api.
0 commit comments