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
2#include <sys/socket.h>2#include <sys/socket.h>
3#include <sys/un.h>3#include <sys/un.h>
4 4
5#ifdef __linux__
6#include <linux/vm_sockets.h>
7#endif
8
5#include <netinet/in.h>9#include <netinet/in.h>
6#include <netinet/tcp.h>10#include <netinet/tcp.h>
7#include <netdb.h>11#include <netdb.h>
@@ -461,12 +465,15 @@ struct fuse_operations fsops = { · 453 unmodified lines
461 .chmod = fschmod465 .chmod = fschmod
462};466};
463 467
464static int uflag, tflag;468static int uflag, tflag, vflag;
465 469
466static void470static void
467doconnect(char *name, char *port)471doconnect(char *name, char *port)
468{472{
469 struct sockaddr_un uaddr;473 struct sockaddr_un uaddr;
474#ifdef __linux__
475 struct sockaddr_vm vaddr;
476#endif
470 struct addrinfo *a, *ainfo, hint;477 struct addrinfo *a, *ainfo, hint;
471 int e, n, yes;478 int e, n, yes;
472 int p1[2], p2[2];479 int p1[2], p2[2];
@@ -509,6 +516,31 @@ doconnect(char *name, char *port) · 36 unmodified lines
509 return;516 return;
510 }517 }
511 518
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
512 memset(&hint, 0, sizeof(hint));544 memset(&hint, 0, sizeof(hint));
513 hint.ai_flags = AI_ADDRCONFIG;545 hint.ai_flags = AI_ADDRCONFIG;
514 hint.ai_family = AF_UNSPEC;546 hint.ai_family = AF_UNSPEC;
@@ -550,7 +582,7 @@ main(int argc, char *argv[]) · 35 unmodified lines
550 if((pw = getpwuid(getuid())) == NULL)582 if((pw = getpwuid(getuid())) == NULL)
551 errx(1, "Could not get user");583 errx(1, "Could not get user");
552 strecpy(user, user+sizeof(user), pw->pw_name);584 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){
554 switch(ch){586 switch(ch){
555 case 'd':587 case 'd':
556 debug++;588 debug++;
@@ -561,6 +593,13 @@ main(int argc, char *argv[]) · 4 unmodified lines
561 case 'U':593 case 'U':
562 uflag++;594 uflag++;
563 break;595 break;
596 case 'V':
597#ifdef __linux__
598 vflag++;
599#else
600 errx(2, "vsock not supported on this platform");
601#endif
602 break;
564 case 'T':603 case 'T':
565 tflag++;604 tflag++;
566 break;605 break;
@@ -732,6 +771,6 @@ breakpath(char *dname) · 165 unmodified lines
732void771void
733usage(void)772usage(void)
734{773{
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");
736 exit(2);775 exit(2);
737}776}

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