History

add vsock support

Matus Skvarla committed 1 year ago

Commit 4a974cf1 parent af2e8201 file · +42 −3Browse files

Unified · Split

9pfs.c+42−3
@@ -2,6 +2,10 @@ · 1 unmodified line
22 #include <sys/socket.h>
33 #include <sys/un.h>
44
5+#ifdef __linux__
6+#include <linux/vm_sockets.h>
7+#endif
8+
59 #include <netinet/in.h>
610 #include <netinet/tcp.h>
711 #include <netdb.h>
@@ -461,12 +465,15 @@ struct fuse_operations fsops = { · 453 unmodified lines
461465 .chmod = fschmod
462466 };
463467
464−static int uflag, tflag;
468+static int uflag, tflag, vflag;
465469
466470 static void
467471 doconnect(char *name, char *port)
468472 {
469473 struct sockaddr_un uaddr;
474+#ifdef __linux__
475+ struct sockaddr_vm vaddr;
476+#endif
470477 struct addrinfo *a, *ainfo, hint;
471478 int e, n, yes;
472479 int p1[2], p2[2];
@@ -509,6 +516,31 @@ doconnect(char *name, char *port) · 36 unmodified lines
509516 return;
510517 }
511518
519+#ifdef __linux__
520+ if(vflag){
521+ long cid = strtol(name, NULL, 10);
522+ if(cid < 0 || cid > UINT32_MAX){
523+ errx(1, "parsing service as vsock cid");
524+ }
525+
526+ long intport = strtol(port, NULL, 10);
527+ if(intport <= 0 || intport > UINT32_MAX){
528+ errx(1, "parsing vsock port");
529+ }
530+
531+ memset(&vaddr, 0, sizeof(struct sockaddr_vm));
532+ vaddr.svm_family = AF_VSOCK;
533+ vaddr.svm_cid = cid;
534+ vaddr.svm_port = intport;
535+
536+ infd = outfd = socket(AF_VSOCK, SOCK_STREAM, 0);
537+ if(connect(infd, (struct sockaddr *)&vaddr, sizeof(struct sockaddr_vm)) == -1)
538+ goto err;
539+
540+ return;
541+ }
542+#endif
543+
512544 memset(&hint, 0, sizeof(hint));
513545 hint.ai_flags = AI_ADDRCONFIG;
514546 hint.ai_family = AF_UNSPEC;
@@ -550,7 +582,7 @@ main(int argc, char *argv[]) · 35 unmodified lines
550582 if((pw = getpwuid(getuid())) == NULL)
551583 errx(1, "Could not get user");
552584 strecpy(user, user+sizeof(user), pw->pw_name);
553− while((ch = getopt(argc, argv, ":dnUTap:u:A:o:f")) != -1){
585+ while((ch = getopt(argc, argv, ":dnUVTap:u:A:o:f")) != -1){
554586 switch(ch){
555587 case 'd':
556588 debug++;
@@ -561,6 +593,13 @@ main(int argc, char *argv[]) · 4 unmodified lines
561593 case 'U':
562594 uflag++;
563595 break;
596+ case 'V':
597+#ifdef __linux__
598+ vflag++;
599+#else
600+ errx(2, "vsock not supported on this platform");
601+#endif
602+ break;
564603 case 'T':
565604 tflag++;
566605 break;
@@ -732,6 +771,6 @@ breakpath(char *dname) · 165 unmodified lines
732771 void
733772 usage(void)
734773 {
735− fprintf(stderr, "Usage: 9pfs [-anUfd] [-A aname] [-p port] [-u user] [-o option] service mtpt\n");
774+ fprintf(stderr, "Usage: 9pfs [-anUVfd] [-A aname] [-p port] [-u user] [-o option] service mtpt\n");
736775 exit(2);
737776 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t