Add the option for a socket node to shut down when the last hook
to an adjoining node is removed. Also move file scope definitions back within the file, and remove un-needed include file.
This commit is contained in:
parent
7f6b8c3d04
commit
45168c5d16
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=52885
@ -69,7 +69,6 @@
|
||||
#include <netgraph/ng_message.h>
|
||||
#include <netgraph/netgraph.h>
|
||||
#include <netgraph/ng_socket.h>
|
||||
#include <netgraph/ng_socketvar.h>
|
||||
|
||||
/*
|
||||
* It's Ascii-art time!
|
||||
@ -97,12 +96,31 @@
|
||||
* +----------------+
|
||||
*/
|
||||
|
||||
/* Netgraph protocol control block for each socket */
|
||||
struct ngpcb {
|
||||
struct socket *ng_socket; /* the socket */
|
||||
struct ngsock *sockdata; /* netgraph info */
|
||||
LIST_ENTRY(ngpcb) socks; /* linked list of sockets */
|
||||
int type; /* NG_CONTROL or NG_DATA */
|
||||
};
|
||||
|
||||
/* Per-node private data */
|
||||
struct ngsock {
|
||||
struct ng_node *node; /* the associated netgraph node */
|
||||
struct ngpcb *datasock; /* optional data socket */
|
||||
struct ngpcb *ctlsock; /* optional control socket */
|
||||
int flags;
|
||||
int refs;
|
||||
};
|
||||
#define NGS_FLAG_NOLINGER 1 /* close with last hook */
|
||||
|
||||
/* Netgraph node methods */
|
||||
static ng_constructor_t ngs_constructor;
|
||||
static ng_rcvmsg_t ngs_rcvmsg;
|
||||
static ng_shutdown_t ngs_rmnode;
|
||||
static ng_newhook_t ngs_newhook;
|
||||
static ng_rcvdata_t ngs_rcvdata;
|
||||
static ng_disconnect_t ngs_disconnect;
|
||||
|
||||
/* Internal methods */
|
||||
static int ng_attach_data(struct socket *so);
|
||||
@ -132,7 +150,7 @@ static struct ng_type typestruct = {
|
||||
NULL,
|
||||
ngs_rcvdata,
|
||||
ngs_rcvdata,
|
||||
NULL,
|
||||
ngs_disconnect
|
||||
};
|
||||
NETGRAPH_INIT(socket, &typestruct);
|
||||
|
||||
@ -706,6 +724,7 @@ ngs_newhook(node_p node, hook_p hook, const char *name)
|
||||
|
||||
/*
|
||||
* Incoming messages get passed up to the control socket.
|
||||
* Unless they are for us specifically (socket_type)
|
||||
*/
|
||||
static int
|
||||
ngs_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
|
||||
@ -724,6 +743,22 @@ ngs_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr,
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
if (msg->header.typecookie == NGM_SOCKET_COOKIE) {
|
||||
switch (msg->header.cmd) {
|
||||
case NGM_SOCK_CMD_NOLINGER:
|
||||
sockdata->flags |= NGS_FLAG_NOLINGER;
|
||||
break;
|
||||
case NGM_SOCK_CMD_LINGER:
|
||||
sockdata->flags &= ~NGS_FLAG_NOLINGER;
|
||||
break;
|
||||
default:
|
||||
error = EINVAL; /* unknown command */
|
||||
}
|
||||
/* Free the message and return */
|
||||
FREE(msg, M_NETGRAPH);
|
||||
return(error);
|
||||
|
||||
}
|
||||
/* Get the return address into a sockaddr */
|
||||
if ((retaddr == NULL) || (*retaddr == '\0'))
|
||||
retaddr = "";
|
||||
@ -785,6 +820,24 @@ ngs_rcvdata(hook_p hook, struct mbuf *m, meta_p meta)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dook disconnection
|
||||
*
|
||||
* For this type, removal of the last link destroys the node
|
||||
* if the NOLINGER flag is set.
|
||||
*/
|
||||
static int
|
||||
ngs_disconnect(hook_p hook)
|
||||
{
|
||||
struct ngsock *const sockdata = hook->node->private;
|
||||
|
||||
if ((sockdata->flags & NGS_FLAG_NOLINGER )
|
||||
&& (hook->node->numhooks == 0)) {
|
||||
ng_rmnode(hook->node);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Do local shutdown processing.
|
||||
* In this case, that involves making sure the socket
|
||||
|
@ -51,6 +51,14 @@
|
||||
#define NG_DATA 1
|
||||
#define NG_CONTROL 2
|
||||
|
||||
/* Commands */
|
||||
enum {
|
||||
NGM_SOCK_CMD_NOLINGER = 1, /* close the soket on with last hook */
|
||||
NGM_SOCK_CMD_LINGER /* Keep socket even if 0 hooks */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Netgraph version of struct sockaddr */
|
||||
struct sockaddr_ng {
|
||||
u_char sg_len; /* total length */
|
||||
|
@ -1,63 +0,0 @@
|
||||
|
||||
/*
|
||||
* netgraph.h
|
||||
*
|
||||
* Copyright (c) 1996-1999 Whistle Communications, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Subject to the following obligations and disclaimer of warranty, use and
|
||||
* redistribution of this software, in source or object code forms, with or
|
||||
* without modifications are expressly permitted by Whistle Communications;
|
||||
* provided, however, that:
|
||||
* 1. Any and all reproductions of the source or object code must include the
|
||||
* copyright notice above and the following disclaimer of warranties; and
|
||||
* 2. No rights are granted, in any manner or form, to use Whistle
|
||||
* Communications, Inc. trademarks, including the mark "WHISTLE
|
||||
* COMMUNICATIONS" on advertising, endorsements, or otherwise except as
|
||||
* such appears in the above copyright notice or in the software.
|
||||
*
|
||||
* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
|
||||
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
|
||||
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
||||
* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
|
||||
* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
|
||||
* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
|
||||
* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
|
||||
* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
|
||||
* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* Author: Julian Elischer <julian@whistle.com>
|
||||
*
|
||||
* $FreeBSD$
|
||||
* $Whistle: ng_socketvar.h,v 1.1 1999/01/20 21:35:39 archie Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NETGRAPH_NG_SOCKETVAR_H_
|
||||
#define _NETGRAPH_NG_SOCKETVAR_H_ 1
|
||||
|
||||
/* Netgraph protocol control block for each socket */
|
||||
struct ngpcb {
|
||||
struct socket *ng_socket; /* the socket */
|
||||
struct ngsock *sockdata; /* netgraph info */
|
||||
LIST_ENTRY(ngpcb) socks; /* linked list of sockets */
|
||||
int type; /* NG_CONTROL or NG_DATA */
|
||||
};
|
||||
|
||||
/* Per-node private data */
|
||||
struct ngsock {
|
||||
struct ng_node *node; /* the associated netgraph node */
|
||||
struct ngpcb *datasock; /* optional data socket */
|
||||
struct ngpcb *ctlsock; /* optional control socket */
|
||||
int refs;
|
||||
};
|
||||
|
||||
#endif /* _NETGRAPH_NG_SOCKETVAR_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user