svc_udp.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* svc_udp.c,
* achieving execute-at-most-once semantics.)
*/
#include <rpc/clnt_soc.h>
#include <errno.h>
#include <syslog.h>
#include <malloc.h>
#include <stdio.h>
static struct xp_ops *svcudp_ops();
extern int errno;
extern SVCXPRT *svc_xprt_alloc();
extern void svc_xprt_free();
extern int _socket(int, int, int);
extern int _getsockname(int, struct sockaddr *, int *);
extern int _listen(int, int);
extern int bindresvport(int, struct sockaddr_in *);
extern int _recvfrom(int, char *, int, int,
struct sockaddr *, int *);
extern int _sendto(int, const char *, int, int,
const struct sockaddr *, int);
char **, uint_t *);
/*
* kept in xprt->xp_p2
*/
struct svcudp_data {
char * su_cache; /* cached data, NULL if no cache */
};
/*
* Usage:
* xprt = svcudp_create(sock);
*
* If sock<0 then a socket is created, else sock is used.
* If the socket, sock is not bound to a port then svcudp_create
* binds it to an arbitrary port. In any (successful) case,
* xprt->xp_sock is the registered socket number and xprt->xp_port is the
* associated port number.
* Once *xprt is initialized, it is registered as a transporter;
* see (svc.h, xprt_register).
* The routines returns NULL if a problem occurred.
*/
SVCXPRT *
register int sock;
{
register struct svcudp_data *su;
struct sockaddr_in addr;
int len = sizeof (struct sockaddr_in);
if (sock == RPC_ANYSOCK) {
" creation problem: %m");
}
}
}
" cannot getsockname: %m");
if (madesock)
}
xprt = svc_xprt_alloc();
if (madesock)
}
if (madesock)
}
if (madesock)
}
return (xprt);
}
SVCXPRT *
int sock;
{
}
static enum xprt_stat
{
return (XPRT_IDLE);
}
static bool_t
{
register int rlen;
char *reply;
goto again;
return (FALSE);
XDR_SETPOS(xdrs, 0);
return (FALSE);
xprt->xp_addrlen);
return (TRUE);
}
}
return (TRUE);
}
static bool_t
{
register int slen;
XDR_SETPOS(xdrs, 0);
== slen) {
}
}
}
return (stat);
}
static bool_t
{
}
static bool_t
{
}
static void
{
}
/* **********this could be a separate file********************* */
/*
* Fifo cache for udp server
* Copies pointers to reply buffers into fifo cache
* Buffers are sent again if retransmissions are detected.
*/
/*
* An entry in the cache
*/
typedef struct cache_node *cache_ptr;
struct cache_node {
/*
* Index into cache is xid, proc, vers, prog and address
*/
struct sockaddr_in cache_addr;
/*
* The cached reply and length
*/
char * cache_reply;
/*
* Next node on the list, if there is a collision
*/
};
/*
* The entire cache
*/
struct udp_cache {
};
/*
* the hashing function
*/
/*
* Enable use of the cache.
* Note: there is no disable.
*/
int
{
return (0);
}
return (0);
}
uc->uc_nextvictim = 0;
" allocate cache data");
return (0);
}
" allocate cache fifo");
return (0);
}
return (1);
}
/*
* Set an entry in the cache
*/
static void
{
char *newbuf;
/*
* Find space for the new entry, either by
* reusing an old entry, or by mallocing a new one
*/
;
return;
}
} else {
" failed");
return;
}
" allocate new rpc_buffer");
return;
}
}
/*
* Store it away
*/
}
/*
* Try to get an entry from the cache
* return 1 if found, 0 if not found
*/
static int
char **replyp;
{
return (1);
}
}
/*
* Failed to find entry
* Remember a few things so we can do a set later
*/
sizeof (struct sockaddr_in));
return (0);
}
static struct xp_ops *
{
}
return (&ops);
}