diff options
author | Olaf Kirch <okir@suse.de> | 2008-09-16 10:08:35 -0400 |
---|---|---|
committer | Steve Dickson <steved@redhat.com> | 2008-09-16 10:08:35 -0400 |
commit | 3e4c74ab527375f37b6633f528e7eab0c363967b (patch) | |
tree | b961f34190b0ac959b22bf61384aa711b1604880 | |
parent | 3942a3b4dcd451a2c41ad95a45f3f1462cb3f133 (diff) | |
download | rpcbind-3e4c74ab527375f37b6633f528e7eab0c363967b.tar.gz |
Introduce helpers for ipprot/netid mapping
There's a couple of places in the portmap emulation code
where we translate between ip protocol numbers and netids.
Encapsulate these in two helper functions:
extern char *pmap_ipprot2netid(int);
extern int pmap_netid2ipprot(const char *);
Signed-off-by: okir@suse.de
Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r-- | src/pmap_svc.c | 37 | ||||
-rw-r--r-- | src/rpcb_svc_com.c | 20 | ||||
-rw-r--r-- | src/rpcbind.h | 2 |
3 files changed, 35 insertions, 24 deletions
diff --git a/src/pmap_svc.c b/src/pmap_svc.c index 99ce508..02a57d2 100644 --- a/src/pmap_svc.c +++ b/src/pmap_svc.c @@ -211,11 +211,8 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long if (op == PMAPPROC_SET) { char buf[32]; - if (reg.pm_prot == IPPROTO_UDP) { - rpcbreg.r_netid = udptrans; - } else if (reg.pm_prot == IPPROTO_TCP) { - rpcbreg.r_netid = tcptrans; - } else { + rpcbreg.r_netid = pmap_ipprot2netid(reg.pm_prot); + if (rpcbreg.r_netid == NULL) { ans = FALSE; goto done_change; } @@ -289,7 +286,8 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt) svc_getrpccaller(xprt)); fprintf(stderr, "PMAP_GETPORT req for (%lu, %lu, %s) from %s :", reg.pm_prog, reg.pm_vers, - reg.pm_prot == IPPROTO_UDP ? "udp" : "tcp", uaddr); + pmap_ipprot2netid(reg.pm_prot)?: "<invalid>", + uaddr); free(uaddr); } #endif @@ -299,12 +297,13 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt) char *pt1, *pt2; char *netid; + netid = pmap_ipprot2netid(reg.pm_prot); + if (netid == NULL) + goto sendreply; if (reg.pm_prot == IPPROTO_UDP) { ua = udp_uaddr; - netid = udptrans; } else { ua = tcp_uaddr; /* To get the len */ - netid = tcptrans; } if (ua == NULL) { goto sendreply; @@ -341,7 +340,7 @@ sendreply: fprintf(stderr, "port = %d\n", port); #endif rpcbs_getaddr(RPCBVERS_2_STAT, reg.pm_prog, reg.pm_vers, - reg.pm_prot == IPPROTO_UDP ? udptrans : tcptrans, + pmap_ipprot2netid(reg.pm_prot) ?: "<unknown>", port ? udptrans : ""); return (TRUE); @@ -372,4 +371,24 @@ pmapproc_dump(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt) return (TRUE); } +int pmap_netid2ipprot(const char *netid) +{ + if (!netid) + return 0; + if (strcmp(netid, tcptrans) == 0) + return IPPROTO_TCP; + if (strcmp(netid, udptrans) == 0) + return IPPROTO_UDP; + return 0; +} + +char *pmap_ipprot2netid(unsigned long proto) +{ + if (proto == IPPROTO_UDP) + return udptrans; + if (proto == IPPROTO_TCP) + return tcptrans; + return NULL; +} + #endif /* PORTMAP */ diff --git a/src/rpcb_svc_com.c b/src/rpcb_svc_com.c index 8f6b4c7..08aa194 100644 --- a/src/rpcb_svc_com.c +++ b/src/rpcb_svc_com.c @@ -1416,13 +1416,8 @@ add_pmaplist(RPCB *arg) struct pmap pmap; struct pmaplist *pml; - if (strcmp(arg->r_netid, udptrans) == 0) { - /* It is UDP! */ - pmap.pm_prot = IPPROTO_UDP; - } else if (strcmp(arg->r_netid, tcptrans) == 0) { - /* It is TCP */ - pmap.pm_prot = IPPROTO_TCP; - } else + pmap.pm_prot = pmap_netid2ipprot(arg->r_netid); + if (!pmap.pm_prot) /* Not an IP protocol */ return (0); @@ -1464,15 +1459,10 @@ del_pmaplist(RPCB *arg) struct pmaplist *prevpml, *fnd; unsigned long prot; - if (strcmp(arg->r_netid, udptrans) == 0) { - /* It is UDP! */ - prot = IPPROTO_UDP; - } else if (strcmp(arg->r_netid, tcptrans) == 0) { - /* It is TCP */ - prot = IPPROTO_TCP; - } else if (arg->r_netid[0] == 0) { + if (arg->r_netid[0] == 0) { prot = 0; /* Remove all occurrences */ - } else { + } else + if ((prot = pmap_netid2ipprot(arg->r_netid)) == 0) { /* Not an IP protocol */ return (0); } diff --git a/src/rpcbind.h b/src/rpcbind.h index 84deba0..58ab3ef 100644 --- a/src/rpcbind.h +++ b/src/rpcbind.h @@ -78,6 +78,8 @@ extern char *udptrans; /* Name of UDP transport */ extern char *tcptrans; /* Name of TCP transport */ extern char *udp_uaddr; /* Universal UDP address */ extern char *tcp_uaddr; /* Universal TCP address */ +extern char *pmap_ipprot2netid(unsigned long); +extern int pmap_netid2ipprot(const char *); #endif int add_bndlist(struct netconfig *, struct netbuf *); |