RPC_SVC_REG(3)

πŸ’– RPC_SVC_REG(3) β€” library routines for registering servers πŸ’–

okay bestie, this is a page from the Library Functions Manual and it's literally all about letting your RPC server register itself so the world can find it. pull up a chair, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

rpc_svc_reg, rpc_reg, svc_reg, svc_unreg, svc_auth_reg, xprt_register, xprt_unregister β€” library routines for registering servers


✨ SYNOPSIS ✨

#include <rpc/rpc.h>

int
rpc_reg(rpcprog_t prognum, rpcvers_t versnum, rpcproc_t procnum,
    char *(*procname)(), xdrproc_t inproc, xdrproc_t outproc,
    char *nettype);

bool_t
svc_reg(SVCXPRT *xprt, const rpcprog_t prognum, const rpcvers_t versnum,
    void (*dispatch)(struct svc_req *, SVCXPRT *),
    const struct netconfig *netconf);

void
svc_unreg(const rpcprog_t prognum, const rpcvers_t versnum);

int
svc_auth_reg(int cred_flavor,
    enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *));

void
xprt_register(SVCXPRT *xprt);

void
xprt_unregister(SVCXPRT *xprt);

✨ DESCRIPTION ✨

so here's the vibe: these routines are part of the RPC library, and what they do is let RPC servers register themselves with rpcbind (peep rpcbind(8) for that one), and pair up a given program + version number with the dispatch function. then, when the RPC server gets an RPC request, the library calls the dispatch routine with the appropriate arguments. that's the whole thing. πŸ’…

πŸŽ€ Routines πŸŽ€

for the definition of the SVCXPRT data structure, go look at rpc(3) β€” not me explaining it twice.

  • rpc_reg() β€” registers program prognum, procedure procname, and version versnum with the RPC service package. so if a request rolls up asking for program prognum, version versnum, and procedure procnum, then procname gets called with a pointer to its argument(s). procname should return a pointer to its static result(s) β€” yes, static, noted. inproc is the XDR function used to decode the arguments, and outproc is the XDR function used to encode the results. procedures get registered on all available transports of the class nettype. see rpc(3). returns 0 if the registration succeeded, -1 otherwise.
  • svc_reg() β€” associates prognum and versnum with the service dispatch procedure, dispatch. if netconf is NULL, the service is not registered with the rpcbind(8) service. if netconf is non-zero, then a mapping of the triple [prognum, versnum, netconf->nc_netid] to xprt->xp_ltaddr is established with the local rpcbind service. returns 1 if it succeeds, and 0 otherwise. slay.
  • svc_unreg() β€” removes from the rpcbind service all mappings of the triple [prognum, versnum, all-transports] to network address, plus all mappings within the RPC service package of the double [prognum, versnum] to dispatch routines. bye bye πŸ‘‹
  • svc_auth_reg() β€” registers the service authentication routine handler with the dispatch mechanism, so it can be invoked to authenticate RPC requests received with authentication type cred_flavor. this interface is the whole point of letting developers add new authentication types to their RPC applications without needing to modify the libraries. heads up tho: service implementors usually do not need this routine.

typical service application would call svc_auth_reg() after registering the service and prior to calling svc_run(). when it's needed to process an RPC credential of type cred_flavor, the handler procedure gets called with two arguments β€” struct svc_req *rqst and struct rpc_msg *msg β€” and is expected to return a valid enum auth_stat value.

🚨 real talk: there is no provision to change or delete an authentication handler once registered. once it's in, it's in. periodt.

returns 0 if the registration is successful, 1 if cred_flavor already has an authentication handler registered for it, and -1 otherwise.

  • xprt_register() β€” after the RPC service transport handle xprt is created, it gets registered with the RPC service package. this routine modifies the global variable svc_fdset (go see rpc_svc_calls(3)). service implementors usually do not need this routine.
  • xprt_unregister() β€” before an RPC service transport handle xprt is destroyed, it unregisters itself with the RPC service package. this routine modifies the global variable svc_fdset (again, rpc_svc_calls(3)). service implementors usually do not need this routine either.

✨ AVAILABILITY ✨

these functions are part of libtirpc. iconic behavior honestly. 🫢


✨ SEE ALSO ✨


and that's a wrap bestie!! this one came from the Debian crew, dated May 3, 1993 β€” yeah she's vintage, she's a classic, and she still ate πŸ’…βœ¨ go register your servers, you've got this πŸ’–πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from