-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This address family is used in communication between virtual machines and their hosts. Advantages include that no virtual ethernet adapter and their respective address configuration and routing need to be setup. Rather, with this new link type, only a single yggdrasil interface can exist inside of the virtual machine. It can also be used inside of containers. There, the advantage over existing link types like unix sockets include, that no mount point need to be shared with the host and container. This provides more isolation. More information: https://man7.org/linux/man-pages/man7/vsock.7.html https://gist.github.com/nrdmn/7971be650919b112343b1cb2757a3fe6
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 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
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,69 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"net/url" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/Arceliar/phony" | ||
"github.com/mdlayher/vsock" | ||
) | ||
|
||
type linkVSOCK struct { | ||
phony.Inbox | ||
*links | ||
} | ||
|
||
func (l *links) newLinkVSOCK() *linkVSOCK { | ||
lt := &linkVSOCK{ | ||
links: l, | ||
} | ||
return lt | ||
} | ||
|
||
func (l *linkVSOCK) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) { | ||
localPort, err := strconv.Atoi(url.Port()) | ||
if err != nil { | ||
return nil, fmt.Errorf("no VSOCK port specified: %w", err) | ||
} | ||
contextId, err := urlParseContextId(url) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unknown VSOCK host and cannot parse as numerical contextID: %w", err) | ||
} | ||
return vsock.Dial(contextId, uint32(localPort), nil) | ||
Check failure Code scanning / CodeQL Incorrect conversion between integer types High
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi Error loading related location Loading |
||
} | ||
|
||
func (l *linkVSOCK) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) { | ||
localPort, err := strconv.Atoi(url.Port()) | ||
if err != nil { | ||
return nil, fmt.Errorf("no VSOCK port specified: %w", err) | ||
} | ||
contextId, err := urlParseContextId(url) | ||
if err != nil { | ||
return nil, fmt.Errorf("Unknown VSOCK host and cannot parse as numerical contextID: %w", err) | ||
} | ||
return vsock.ListenContextID(contextId, uint32(localPort), nil) | ||
Check failure Code scanning / CodeQL Incorrect conversion between integer types High
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi Error loading related location Loading |
||
} | ||
|
||
func urlParseContextId(u *url.URL) (uint32, error) { | ||
var contextId uint32 | ||
|
||
switch strings.ToLower(u.Hostname()) { | ||
case "hypervisor": | ||
contextId = vsock.Hypervisor | ||
case "local": | ||
contextId = vsock.Local | ||
case "host": | ||
contextId = vsock.Host | ||
default: | ||
parsedHost, err := strconv.Atoi(u.Hostname()) | ||
if err != nil { | ||
return 0, err | ||
} | ||
contextId = uint32(parsedHost) | ||
Check failure Code scanning / CodeQL Incorrect conversion between integer types High
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi Error loading related location Loading |
||
} | ||
return contextId, nil | ||
} |