Make route and netstat share the same struct progops (and initialization

code)
This commit is contained in:
martin 2020-04-03 16:20:51 +00:00
parent d79fbfb9e8
commit af2ed9cf6e
6 changed files with 55 additions and 93 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: prog_ops.h,v 1.4 2020/04/02 18:32:31 christos Exp $ */
/* $NetBSD: prog_ops.h,v 1.5 2020/04/03 16:20:52 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -30,9 +30,13 @@
#define _PROG_OPS_H_
#include <sys/types.h>
#include <sys/sysctl.h>
#ifndef CRUNCHOPS
/* XXX: Keep same order with netstat! */
/*
* This is shared between netstat and route (as they share some code)
*/
struct sysctlnode;
struct prog_ops {
int (*op_init)(void);
@ -46,10 +50,18 @@ struct prog_ops {
ssize_t (*op_read)(int, void *, size_t);
ssize_t (*op_write)(int, const void *, size_t);
int (*op_shutdown)(int, int);
int (*op_sysctl)(const int *, u_int, void *, size_t *,
const void *, size_t);
int (*op_shutdown)(int, int);
int (*op_sysctlbyname)(const char *, void *, size_t *,
const void *, size_t);
int (*op_sysctlgetmibinfo)(const char *, int *, u_int *,
char *, size_t *, struct sysctlnode **, int);
int (*op_sysctlnametomib)(const char *, int *, size_t *);
};
extern const struct prog_ops prog_ops;
@ -64,9 +76,13 @@ extern const struct prog_ops prog_ops;
#define prog_read prog_ops.op_read
#define prog_write prog_ops.op_write
#define prog_shutdown prog_ops.op_shutdown
#define prog_sysctl prog_ops.op_sysctl
#define prog_shutdown prog_ops.op_shutdown
#define prog_sysctlbyname prog_ops.op_sysctlbyname
#define prog_sysctlgetmibinfo prog_ops.op_sysctlgetmibinfo
#define prog_sysctlnametomib prog_ops.op_sysctlnametomib
#else
#define prog_init ((int (*)(void))NULL)
@ -80,8 +96,13 @@ extern const struct prog_ops prog_ops;
#define prog_read read
#define prog_write write
#define prog_sysctl sysctl
#define prog_shutdown shutdown
#define prog_sysctl sysctl
#define prog_sysctlbyname sysctlbyname
#define prog_sysctlgetmibinfo sysctlgetmibinfo
#define prog_sysctlnametomib sysctlnametomib
#endif
#endif /* _PROG_OPS_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: route_hostops.c,v 1.2 2020/04/02 18:32:31 christos Exp $ */
/* $NetBSD: route_hostops.c,v 1.3 2020/04/03 16:20:52 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: route_hostops.c,v 1.2 2020/04/02 18:32:31 christos Exp $");
__RCSID("$NetBSD: route_hostops.c,v 1.3 2020/04/03 16:20:52 martin Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -51,7 +51,13 @@ const struct prog_ops prog_ops = {
.op_read = read,
.op_write = write,
.op_shutdown = shutdown,
.op_sysctl = sysctl,
.op_shutdown = shutdown,
.op_sysctlbyname = sysctlbyname,
.op_sysctlgetmibinfo = sysctlgetmibinfo,
.op_sysctlnametomib = sysctlnametomib,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: route_rumpops.c,v 1.2 2020/04/02 18:32:31 christos Exp $ */
/* $NetBSD: route_rumpops.c,v 1.3 2020/04/03 16:20:52 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: route_rumpops.c,v 1.2 2020/04/02 18:32:31 christos Exp $");
__RCSID("$NetBSD: route_rumpops.c,v 1.3 2020/04/03 16:20:52 martin Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -54,7 +54,17 @@ const struct prog_ops prog_ops = {
.op_read = rump_sys_read,
.op_write = rump_sys_write,
.op_shutdown = rump_sys_shutdown,
.op_sysctl = rump_sys___sysctl,
.op_shutdown = rump_sys_shutdown,
/*
* The following are only indirected through ops because
* santizers get confused otherwise.
*/
.op_sysctlbyname = sysctlbyname,
.op_sysctlgetmibinfo = sysctlgetmibinfo,
.op_sysctlnametomib = sysctlnametomib,
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: netstat_hostops.c,v 1.2 2019/08/18 04:14:40 kamil Exp $ */
/* $NetBSD: netstat_hostops.c,v 1.3 2020/04/03 16:20:51 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -28,20 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: netstat_hostops.c,v 1.2 2019/08/18 04:14:40 kamil Exp $");
__RCSID("$NetBSD: netstat_hostops.c,v 1.3 2020/04/03 16:20:51 martin Exp $");
#endif /* !lint */
#include <sys/types.h>
#include <sys/sysctl.h>
#include "prog_ops.h"
const struct prog_ops prog_ops = {
.op_sysctl = sysctl,
.op_sysctlbyname = sysctlbyname,
.op_sysctlgetmibinfo = sysctlgetmibinfo,
.op_sysctlnametomib = sysctlnametomib,
};
#include "../../sbin/route/route_hostops.c"

View File

@ -1,4 +1,4 @@
/* $NetBSD: netstat_rumpops.c,v 1.2 2019/08/18 04:14:40 kamil Exp $ */
/* $NetBSD: netstat_rumpops.c,v 1.3 2020/04/03 16:20:51 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -26,28 +26,4 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: netstat_rumpops.c,v 1.2 2019/08/18 04:14:40 kamil Exp $");
#endif /* !lint */
#include <sys/types.h>
#include <sys/sysctl.h>
#include <rump/rump.h>
#include <rump/rumpclient.h>
#include <rump/rump_syscalls.h>
#include "prog_ops.h"
const struct prog_ops prog_ops = {
.op_init = rumpclient_init,
.op_sysctl = rump_sys___sysctl,
.op_sysctlbyname = sysctlbyname,
.op_sysctlgetmibinfo = sysctlgetmibinfo,
.op_sysctlnametomib = sysctlnametomib,
};
#include "../../sbin/route/route_rumpops.c"

View File

@ -1,4 +1,4 @@
/* $NetBSD: prog_ops.h,v 1.3 2019/08/18 04:14:40 kamil Exp $ */
/* $NetBSD: prog_ops.h,v 1.4 2020/04/03 16:20:51 martin Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -26,43 +26,5 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _PROG_OPS_H_
#define _PROG_OPS_H_
#include <sys/types.h>
#ifndef CRUNCHOPS
struct sysctlnode;
struct prog_ops {
int (*op_init)(void);
int (*op_sysctl)(const int *, u_int, void *, size_t *,
const void *, size_t);
/* Indirection needed for sanitizers. */
int (*op_sysctlbyname)(const char *, void *, size_t *,
const void *, size_t);
int (*op_sysctlgetmibinfo)(const char *, int *, u_int *,
char *, size_t *, struct sysctlnode **, int);
int (*op_sysctlnametomib)(const char *, int *, size_t *);
};
extern const struct prog_ops prog_ops;
#define prog_init prog_ops.op_init
#define prog_sysctl prog_ops.op_sysctl
#define prog_sysctlbyname prog_ops.op_sysctlbyname
#define prog_sysctlgetmibinfo prog_ops.op_sysctlgetmibinfo
#define prog_sysctlnametomib prog_ops.op_sysctlnametomib
#else
#define prog_init ((int (*)(void))NULL)
#define prog_sysctl sysctl
#define prog_sysctlbyname sysctlbyname
#define prog_sysctlgetmibinfo sysctlgetmibinfo
#define prog_sysctlnametomib sysctlnametomib
#endif
#endif /* _PROG_OPS_H_ */
#include "../../sbin/route/prog_ops.h"