Misc: some updates.

1.add interface `ff_dup` and `ff_dup2`.
2.add interface `ff_ioctl_freebsd`/`ff_getsockopt_freebsd`/`ff_setsockopt_freebsd` for tools.
3.initial parameter `proc-type` can be NULL, default "auto".
This commit is contained in:
whl739 2018-06-10 20:37:34 +08:00
parent c46b4de422
commit dbbea7cad3
6 changed files with 193 additions and 16 deletions

2
.gitignore vendored
View File

@ -20,3 +20,5 @@ lib/machine_include/
lib/vnode_if.h lib/vnode_if.h
lib/vnode_if_newproto.h lib/vnode_if_newproto.h
lib/vnode_if_typedef.h lib/vnode_if_typedef.h
app/nginx-1.11.10/Makefile
app/nginx-1.11.10/objs/

View File

@ -109,6 +109,9 @@ int ff_kevent_do_each(int kq, const struct kevent *changelist, int nchanges,
int ff_gettimeofday(struct timeval *tv, struct timezone *tz); int ff_gettimeofday(struct timeval *tv, struct timezone *tz);
int ff_dup(int oldfd);
int ff_dup2(int oldfd, int newfd);
/* POSIX-LIKE api end */ /* POSIX-LIKE api end */
@ -172,6 +175,13 @@ void ff_regist_packet_dispatcher(dispatch_func_t func);
/* internal api begin */ /* internal api begin */
/* FreeBSD style calls. Used for tools. */
int ff_ioctl_freebsd(int fd, unsigned long request, ...);
int ff_setsockopt_freebsd(int s, int level, int optname,
const void *optval, socklen_t optlen);
int ff_getsockopt_freebsd(int s, int level, int optname,
void *optval, socklen_t *optlen);
/* /*
* Handle rtctl. * Handle rtctl.
* The data is a pointer to struct rt_msghdr. * The data is a pointer to struct rt_msghdr.

5
lib/ff_api.symlist Normal file → Executable file
View File

@ -45,3 +45,8 @@ ff_gettimeofday
ff_fdisused ff_fdisused
ff_getmaxfd ff_getmaxfd
ff_ngctl ff_ngctl
ff_ioctl_freebsd
ff_getsockopt_freebsd
ff_setsockopt_freebsd
ff_dup
ff_dup2

View File

@ -511,9 +511,13 @@ ff_parse_args(struct ff_config *cfg, int argc, char *const argv[])
} }
} }
if (cfg->dpdk.proc_type == NULL || if (cfg->dpdk.proc_type == NULL) {
(strcmp(cfg->dpdk.proc_type, "primary") && cfg->dpdk.proc_type = strdup("auto");
strcmp(cfg->dpdk.proc_type, "secondary"))) { }
if (strcmp(cfg->dpdk.proc_type, "primary") &&
strcmp(cfg->dpdk.proc_type, "secondary") &&
strcmp(cfg->dpdk.proc_type, "auto")) {
printf("invalid proc-type\n"); printf("invalid proc-type\n");
return -1; return -1;
} }

View File

@ -1077,7 +1077,7 @@ handle_ioctl_msg(struct ff_msg *msg)
goto done; goto done;
} }
ret = ff_ioctl(fd, msg->ioctl.cmd, msg->ioctl.data); ret = ff_ioctl_freebsd(fd, msg->ioctl.cmd, msg->ioctl.data);
ff_close(fd); ff_close(fd);
@ -1136,12 +1136,12 @@ handle_ipfw_msg(struct ff_msg *msg)
switch (msg->ipfw.cmd) { switch (msg->ipfw.cmd) {
case FF_IPFW_GET: case FF_IPFW_GET:
ret = ff_getsockopt(fd, msg->ipfw.level, ret = ff_getsockopt_freebsd(fd, msg->ipfw.level,
msg->ipfw.optname, msg->ipfw.optval, msg->ipfw.optname, msg->ipfw.optval,
msg->ipfw.optlen); msg->ipfw.optlen);
break; break;
case FF_IPFW_SET: case FF_IPFW_SET:
ret = ff_setsockopt(fd, msg->ipfw.level, ret = ff_setsockopt_freebsd(fd, msg->ipfw.level,
msg->ipfw.optname, msg->ipfw.optval, msg->ipfw.optname, msg->ipfw.optval,
*(msg->ipfw.optlen)); *(msg->ipfw.optlen));
break; break;

View File

@ -52,6 +52,9 @@
#include <sys/fcntl.h> #include <sys/fcntl.h>
#include <net/route.h> #include <net/route.h>
#include <net/if.h>
#include <sys/sockio.h>
#include <machine/stdarg.h> #include <machine/stdarg.h>
#include "ff_api.h" #include "ff_api.h"
@ -140,6 +143,27 @@
#define LINUX_TIOCPKT_DOSTOP 32 #define LINUX_TIOCPKT_DOSTOP 32
#define LINUX_TIOCPKT_IOCTL 64 #define LINUX_TIOCPKT_IOCTL 64
#define LINUX_SIOCGIFCONF 0x8912
#define LINUX_SIOCGIFFLAGS 0x8913
#define LINUX_SIOCSIFFLAGS 0x8914
#define LINUX_SIOCGIFADDR 0x8915
#define LINUX_SIOCSIFADDR 0x8916
#define LINUX_SIOCGIFDSTADDR 0x8917
#define LINUX_SIOCSIFDSTADDR 0x8918
#define LINUX_SIOCGIFBRDADDR 0x8919
#define LINUX_SIOCSIFBRDADDR 0x891a
#define LINUX_SIOCGIFNETMASK 0x891b
#define LINUX_SIOCSIFNETMASK 0x891c
#define LINUX_SIOCGIFMETRIC 0x891d
#define LINUX_SIOCSIFMETRIC 0x891e
#define LINUX_SIOCGIFMTU 0x8921
#define LINUX_SIOCSIFMTU 0x8922
#define LINUX_SIOCSIFNAME 0x8923
#define LINUX_SIOCADDMULTI 0x8931
#define LINUX_SIOCDELMULTI 0x8932
#define LINUX_SIOCGIFINDEX 0x8933
#define LINUX_SIOCDIFADDR 0x8936
/* ioctl define end */ /* ioctl define end */
@ -217,8 +241,48 @@ linux2freebsd_ioctl(unsigned long request)
return TIOCPKT_DOSTOP; return TIOCPKT_DOSTOP;
case LINUX_TIOCPKT_IOCTL: case LINUX_TIOCPKT_IOCTL:
return TIOCPKT_IOCTL; return TIOCPKT_IOCTL;
case LINUX_SIOCGIFCONF:
return SIOCGIFCONF;
case LINUX_SIOCGIFFLAGS:
return SIOCGIFFLAGS;
case LINUX_SIOCSIFFLAGS:
return SIOCSIFFLAGS;
case LINUX_SIOCGIFADDR:
return SIOCGIFADDR;
case LINUX_SIOCSIFADDR:
return SIOCSIFADDR;
case LINUX_SIOCGIFDSTADDR:
return SIOCGIFDSTADDR;
case LINUX_SIOCSIFDSTADDR:
return SIOCSIFDSTADDR;
case LINUX_SIOCGIFBRDADDR:
return SIOCGIFBRDADDR;
case LINUX_SIOCSIFBRDADDR:
return SIOCSIFBRDADDR;
case LINUX_SIOCGIFNETMASK:
return SIOCGIFNETMASK;
case LINUX_SIOCSIFNETMASK:
return SIOCSIFNETMASK;
case LINUX_SIOCGIFMETRIC:
return SIOCGIFMETRIC;
case LINUX_SIOCSIFMETRIC:
return SIOCSIFMETRIC;
case LINUX_SIOCGIFMTU:
return SIOCGIFMTU;
case LINUX_SIOCSIFMTU:
return SIOCSIFMTU;
case LINUX_SIOCSIFNAME:
return SIOCSIFNAME;
case LINUX_SIOCADDMULTI:
return SIOCADDMULTI;
case LINUX_SIOCDELMULTI:
return SIOCDELMULTI;
case LINUX_SIOCGIFINDEX:
return SIOCGIFINDEX;
case LINUX_SIOCDIFADDR:
return SIOCDIFADDR;
default: default:
return request; return -1;
} }
} }
@ -259,7 +323,7 @@ so_opt_convert(int optname)
case LINUX_SO_PROTOCOL: case LINUX_SO_PROTOCOL:
return SO_PROTOCOL; return SO_PROTOCOL;
default: default:
return optname; return -1;
} }
} }
@ -286,7 +350,7 @@ ip_opt_convert(int optname)
case LINUX_IP_DROP_MEMBERSHIP: case LINUX_IP_DROP_MEMBERSHIP:
return IP_DROP_MEMBERSHIP; return IP_DROP_MEMBERSHIP;
default: default:
return optname; return -1;
} }
} }
@ -307,7 +371,7 @@ tcp_opt_convert(int optname)
case LINUX_TCP_MD5SIG: case LINUX_TCP_MD5SIG:
return TCP_MD5SIG; return TCP_MD5SIG;
default: default:
return optname; return -1;
} }
} }
@ -322,7 +386,7 @@ linux2freebsd_opt(int level, int optname)
case IPPROTO_TCP: case IPPROTO_TCP:
return tcp_opt_convert(optname); return tcp_opt_convert(optname);
default: default:
return optname; return -1;
} }
} }
@ -394,6 +458,23 @@ kern_fail:
return (-1); return (-1);
} }
int
ff_getsockopt_freebsd(int s, int level, int optname,
void *optval, socklen_t *optlen)
{
int rc;
if ((rc = kern_getsockopt(curthread, s, level, optname,
optval, UIO_USERSPACE, optlen)))
goto kern_fail;
return (rc);
kern_fail:
ff_os_errno(rc);
return (-1);
}
int int
ff_setsockopt(int s, int level, int optname, const void *optval, ff_setsockopt(int s, int level, int optname, const void *optval,
socklen_t optlen) socklen_t optlen)
@ -420,6 +501,23 @@ kern_fail:
return (-1); return (-1);
} }
int
ff_setsockopt_freebsd(int s, int level, int optname,
const void *optval, socklen_t optlen)
{
int rc;
if ((rc = kern_setsockopt(curthread, s, level, optname,
__DECONST(void *, optval), UIO_USERSPACE, optlen)))
goto kern_fail;
return (rc);
kern_fail:
ff_os_errno(rc);
return (-1);
}
int int
ff_ioctl(int fd, unsigned long request, ...) ff_ioctl(int fd, unsigned long request, ...)
{ {
@ -447,6 +545,27 @@ kern_fail:
return (-1); return (-1);
} }
int
ff_ioctl_freebsd(int fd, unsigned long request, ...)
{
int rc;
va_list ap;
caddr_t argp;
va_start(ap, request);
argp = va_arg(ap, caddr_t);
va_end(ap);
if ((rc = kern_ioctl(curthread, fd, request, argp)))
goto kern_fail;
return (rc);
kern_fail:
ff_os_errno(rc);
return (-1);
}
int int
ff_close(int fd) ff_close(int fd)
{ {
@ -1037,6 +1156,43 @@ ff_gettimeofday(struct timeval *tv, struct timezone *tz)
return 0; return 0;
} }
int
ff_dup(int oldfd)
{
int rc;
struct dup_args da = {
.fd = oldfd,
};
if ((rc = sys_dup(curthread, &da)))
goto kern_fail;
rc = curthread->td_retval[0];
return (rc);
kern_fail:
ff_os_errno(rc);
return (-1);
}
int
ff_dup2(int oldfd, int newfd)
{
int rc;
struct dup2_args da = {
.from = oldfd,
.to = newfd
};
if ((rc = sys_dup2(curthread, &da)))
goto kern_fail;
rc = curthread->td_retval[0];
return (rc);
kern_fail:
ff_os_errno(rc);
return (-1);
}
int int
ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag, ff_route_ctl(enum FF_ROUTE_CTL req, enum FF_ROUTE_FLAG flag,
struct linux_sockaddr *dst, struct linux_sockaddr *gw, struct linux_sockaddr *dst, struct linux_sockaddr *gw,