summaryrefslogtreecommitdiffstats
path: root/extras/gomemif/memif/control_channel.go
diff options
context:
space:
mode:
authorDaniel Béreš <dberes@cisco.com>2022-07-27 12:22:39 +0000
committerBeno�t Ganne <bganne@cisco.com>2022-10-06 12:22:07 +0000
commit82ec908acbab63af64b1b912babcab9a16d9f0e6 (patch)
tree496d633c09fbb1634ab23bbcc1e9d1efbb6970bb /extras/gomemif/memif/control_channel.go
parenta58055d6b205426780e2737d3d66bbd872732d78 (diff)
gomemif: update to libmemif version 4.0
Type: improvement This patch provides: 1. interrupt mode support, 2. abstract socket support, 3. overriding responder example and divides it to two examples: -icmp_responder_cb -icmp_responder_poll Signed-off-by: Daniel Béreš <dberes@cisco.com> Change-Id: I99c86d053521760c457541fc596ed554f4077608
Diffstat (limited to 'extras/gomemif/memif/control_channel.go')
-rw-r--r--extras/gomemif/memif/control_channel.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/extras/gomemif/memif/control_channel.go b/extras/gomemif/memif/control_channel.go
index 12672e6e2f8..4788fcb5ea5 100644
--- a/extras/gomemif/memif/control_channel.go
+++ b/extras/gomemif/memif/control_channel.go
@@ -67,11 +67,22 @@ type Socket struct {
interfaceList *list.List
ccList *list.List
epfd int
+ interruptfd int
wakeEvent syscall.EpollEvent
stopPollChan chan struct{}
wg sync.WaitGroup
}
+type interrupt struct {
+ socket *Socket
+ event syscall.EpollEvent
+}
+
+type memifInterrupt struct {
+ connection *Socket
+ qid uint16
+}
+
// StopPolling stops polling events on the socket
func (socket *Socket) StopPolling() error {
if socket.stopPollChan != nil {
@@ -220,6 +231,15 @@ func (socket *Socket) handleEvent(event *syscall.EpollEvent) error {
if socket.listener != nil && socket.listener.event.Fd == event.Fd {
return socket.listener.handleEvent(event)
}
+ intf := socket.interfaceList.Back().Value.(*Interface)
+ if intf.args.InterruptFunc != nil {
+ if int(event.Fd) == int(intf.args.InterruptFd) {
+ b := make([]byte, 8)
+ syscall.Read(int(event.Fd), b)
+ intf.onInterrupt(intf)
+ return nil
+ }
+ }
for elt := socket.ccList.Front(); elt != nil; elt = elt.Next() {
cc, ok := elt.Value.(*controlChannel)
@@ -233,6 +253,25 @@ func (socket *Socket) handleEvent(event *syscall.EpollEvent) error {
return fmt.Errorf(errorFdNotFound)
}
+func (socket *Socket) addInterrupt(fd int) (err error) {
+ l := &interrupt{
+ // we will need this to look up master interface by id
+ socket: socket,
+ }
+
+ l.event = syscall.EpollEvent{
+ Events: syscall.EPOLLIN,
+ Fd: int32(fd),
+ }
+ err = socket.addEvent(&l.event)
+ if err != nil {
+ return fmt.Errorf("Failed to add event: ", err)
+ }
+
+ return nil
+
+}
+
// handleEvent handles epoll event for listener
func (l *listener) handleEvent(event *syscall.EpollEvent) error {
// hang up
@@ -725,7 +764,6 @@ func (cc *controlChannel) parseConnect() (err error) {
if err != nil {
return err
}
-
cc.isConnected = true
return nil
@@ -764,7 +802,6 @@ func (cc *controlChannel) parseConnected() (err error) {
if err != nil {
return err
}
-
cc.isConnected = true
return nil