-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
underlay: support SockOptInt on all platforms incl Windows (#4610)
There is an issue that `syscall.GetsockoptInt` and `syscall.SetsockoptInt` have different signatures on windows than on all other platforms. One fix is to have extra windows code to support this. In the end it would be great to have Windows support for all SCION services, too. The issue popped up when building the router, not sure if it affects other services.
- Loading branch information
1 parent
e88ddce
commit 79e7080
Showing
5 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 ETH Zurich | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// In Windows, SetSockOptInt and GetSockOptInt require syscall.Handle instead of int. | ||
//go:build windows | ||
|
||
package sockctrl | ||
|
||
import ( | ||
"net" | ||
"syscall" | ||
|
||
"github.com/scionproto/scion/pkg/private/serrors" | ||
) | ||
|
||
func SockControl(c *net.UDPConn, f func(syscall.Handle) error) error { | ||
rawConn, err := c.SyscallConn() | ||
if err != nil { | ||
return serrors.Wrap("sockctrl: error accessing raw connection", err) | ||
} | ||
var ctrlErr error | ||
err = rawConn.Control(func(fd uintptr) { | ||
ctrlErr = f(syscall.Handle(fd)) | ||
}) | ||
if err != nil { | ||
return serrors.Wrap("sockctrl: RawConn.Control error", err) | ||
} | ||
if ctrlErr != nil { | ||
return serrors.Wrap("sockctrl: control function error", ctrlErr) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 ETH Zurich | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// In Windows, SetSockOptInt and GetSockOptInt require syscall.Handle instead of int. | ||
//go:build windows | ||
|
||
package sockctrl | ||
|
||
import ( | ||
"net" | ||
"syscall" | ||
) | ||
|
||
func GetsockoptInt(c *net.UDPConn, level, opt int) (int, error) { | ||
var val int | ||
err := SockControl(c, func(fd syscall.Handle) error { | ||
var err error | ||
val, err = syscall.GetsockoptInt(fd, level, opt) | ||
return err | ||
}) | ||
return val, err | ||
} | ||
|
||
func SetsockoptInt(c *net.UDPConn, level, opt, value int) error { | ||
return SockControl(c, func(fd syscall.Handle) error { | ||
return syscall.SetsockoptInt(fd, level, opt, value) | ||
}) | ||
} |