Home | History | Annotate | Line # | Download | only in rpc.lockd
      1  1.8  dholland /*	$NetBSD: test.c,v 1.8 2016/03/12 02:07:44 dholland Exp $	*/
      2  1.1    scottr 
      3  1.7  dholland #include <sys/cdefs.h>
      4  1.4  christos #include <stdio.h>
      5  1.4  christos #include <string.h>
      6  1.7  dholland #include <err.h>
      7  1.1    scottr #include <rpc/rpc.h>
      8  1.1    scottr #include <rpcsvc/nlm_prot.h>
      9  1.4  christos 
     10  1.1    scottr #ifndef lint
     11  1.2     lukem #if 0
     12  1.2     lukem static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
     13  1.2     lukem static char sccsid[] = "from: * @(#)nlm_prot.x	2.1 88/08/01 4.0 RPCSRC";
     14  1.2     lukem #else
     15  1.8  dholland __RCSID("$NetBSD: test.c,v 1.8 2016/03/12 02:07:44 dholland Exp $");
     16  1.2     lukem #endif
     17  1.1    scottr #endif				/* not lint */
     18  1.1    scottr 
     19  1.1    scottr /* Default timeout can be changed using clnt_control() */
     20  1.1    scottr static struct timeval TIMEOUT = {0, 0};
     21  1.1    scottr 
     22  1.1    scottr nlm_testres *
     23  1.4  christos nlm_test_1(struct nlm_testargs *argp, CLIENT *clnt)
     24  1.1    scottr {
     25  1.5  dholland 	enum clnt_stat st;
     26  1.1    scottr 	static nlm_testres res;
     27  1.1    scottr 
     28  1.4  christos 	(void)memset(&res, 0, sizeof(res));
     29  1.5  dholland 	st = clnt_call(clnt, NLM_TEST, xdr_nlm_testargs, argp, xdr_nlm_testres,
     30  1.5  dholland 			&res, TIMEOUT);
     31  1.5  dholland 	if (st != RPC_SUCCESS)
     32  1.4  christos 		return NULL;
     33  1.4  christos 	return &res;
     34  1.1    scottr }
     35  1.1    scottr 
     36  1.1    scottr 
     37  1.1    scottr nlm_res *
     38  1.4  christos nlm_lock_1(struct nlm_lockargs *argp, CLIENT *clnt)
     39  1.1    scottr {
     40  1.1    scottr 	enum clnt_stat st;
     41  1.1    scottr 	static nlm_res res;
     42  1.1    scottr 
     43  1.4  christos 	(void)memset(&res, 0, sizeof(res));
     44  1.5  dholland 	st = clnt_call(clnt, NLM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
     45  1.5  dholland 			&res, TIMEOUT);
     46  1.5  dholland 	if (st != RPC_SUCCESS) {
     47  1.1    scottr 		printf("clnt_call returns %d\n", st);
     48  1.1    scottr 		clnt_perror(clnt, "humbug");
     49  1.4  christos 		return NULL;
     50  1.1    scottr 	}
     51  1.4  christos 	return &res;
     52  1.1    scottr }
     53  1.1    scottr 
     54  1.1    scottr 
     55  1.1    scottr nlm_res *
     56  1.4  christos nlm_cancel_1(struct nlm_cancargs *argp, CLIENT *clnt)
     57  1.1    scottr {
     58  1.5  dholland 	enum clnt_stat st;
     59  1.1    scottr 	static nlm_res res;
     60  1.1    scottr 
     61  1.4  christos 	(void)memset(&res, 0, sizeof(res));
     62  1.5  dholland 	st = clnt_call(clnt, NLM_CANCEL, xdr_nlm_cancargs, argp, xdr_nlm_res,
     63  1.5  dholland 			&res, TIMEOUT);
     64  1.5  dholland 	if (st != RPC_SUCCESS) {
     65  1.4  christos 		return NULL;
     66  1.1    scottr 	}
     67  1.4  christos 	return &res;
     68  1.1    scottr }
     69  1.1    scottr 
     70  1.1    scottr 
     71  1.1    scottr nlm_res *
     72  1.4  christos nlm_unlock_1(struct nlm_unlockargs *argp, CLIENT *clnt)
     73  1.1    scottr {
     74  1.5  dholland 	enum clnt_stat st;
     75  1.1    scottr 	static nlm_res res;
     76  1.1    scottr 
     77  1.4  christos 	(void)memset(&res, 0, sizeof(res));
     78  1.5  dholland 	st = clnt_call(clnt, NLM_UNLOCK, xdr_nlm_unlockargs, argp, xdr_nlm_res,
     79  1.5  dholland 			&res, TIMEOUT);
     80  1.5  dholland 	if (st != RPC_SUCCESS) {
     81  1.4  christos 		return NULL;
     82  1.1    scottr 	}
     83  1.4  christos 	return &res;
     84  1.1    scottr }
     85  1.1    scottr 
     86  1.1    scottr 
     87  1.1    scottr nlm_res *
     88  1.4  christos nlm_granted_1(struct nlm_testargs *argp, CLIENT *clnt)
     89  1.1    scottr {
     90  1.5  dholland 	enum clnt_stat st;
     91  1.1    scottr 	static nlm_res res;
     92  1.1    scottr 
     93  1.4  christos 	(void)memset(&res, 0, sizeof(res));
     94  1.5  dholland 	st = clnt_call(clnt, NLM_GRANTED, xdr_nlm_testargs, argp, xdr_nlm_res,
     95  1.5  dholland 			&res, TIMEOUT);
     96  1.5  dholland 	if (st != RPC_SUCCESS) {
     97  1.4  christos 		return NULL;
     98  1.1    scottr 	}
     99  1.4  christos 	return &res;
    100  1.1    scottr }
    101  1.1    scottr 
    102  1.1    scottr 
    103  1.4  christos void *
    104  1.4  christos nlm_test_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
    105  1.1    scottr {
    106  1.5  dholland 	enum clnt_stat st;
    107  1.1    scottr 	static char res;
    108  1.1    scottr 
    109  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    110  1.5  dholland 	st = clnt_call(clnt, NLM_TEST_MSG, xdr_nlm_testargs, argp, xdr_void,
    111  1.5  dholland 			&res, TIMEOUT);
    112  1.5  dholland 	if (st != RPC_SUCCESS) {
    113  1.4  christos 		return NULL;
    114  1.1    scottr 	}
    115  1.4  christos 	return &res;
    116  1.1    scottr }
    117  1.1    scottr 
    118  1.1    scottr 
    119  1.4  christos void *
    120  1.4  christos nlm_lock_msg_1(struct nlm_lockargs *argp, CLIENT *clnt)
    121  1.1    scottr {
    122  1.5  dholland 	enum clnt_stat st;
    123  1.1    scottr 	static char res;
    124  1.1    scottr 
    125  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    126  1.5  dholland 	st = clnt_call(clnt, NLM_LOCK_MSG, xdr_nlm_lockargs, argp, xdr_void,
    127  1.5  dholland 			NULL, TIMEOUT);
    128  1.5  dholland 	if (st != RPC_SUCCESS) {
    129  1.1    scottr 		clnt_perror(clnt, "nlm_lock_msg_1");
    130  1.4  christos 		return NULL;
    131  1.1    scottr 	}
    132  1.4  christos 	return &res;
    133  1.1    scottr }
    134  1.1    scottr 
    135  1.1    scottr 
    136  1.4  christos void *
    137  1.4  christos nlm_cancel_msg_1(struct nlm_cancargs *argp, CLIENT *clnt)
    138  1.1    scottr {
    139  1.5  dholland 	enum clnt_stat st;
    140  1.1    scottr 	static char res;
    141  1.1    scottr 
    142  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    143  1.5  dholland 	st = clnt_call(clnt, NLM_CANCEL_MSG, xdr_nlm_cancargs, argp, xdr_void,
    144  1.5  dholland 			&res, TIMEOUT);
    145  1.5  dholland 	if (st != RPC_SUCCESS) {
    146  1.4  christos 		return NULL;
    147  1.1    scottr 	}
    148  1.4  christos 	return &res;
    149  1.1    scottr }
    150  1.1    scottr 
    151  1.1    scottr 
    152  1.4  christos void *
    153  1.4  christos nlm_unlock_msg_1(struct nlm_unlockargs *argp, CLIENT *clnt)
    154  1.1    scottr {
    155  1.5  dholland 	enum clnt_stat st;
    156  1.1    scottr 	static char res;
    157  1.1    scottr 
    158  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    159  1.5  dholland 	st = clnt_call(clnt, NLM_UNLOCK_MSG, xdr_nlm_unlockargs, argp, xdr_void,
    160  1.5  dholland 			&res, TIMEOUT);
    161  1.5  dholland 	if (st != RPC_SUCCESS) {
    162  1.4  christos 		return NULL;
    163  1.1    scottr 	}
    164  1.4  christos 	return &res;
    165  1.1    scottr }
    166  1.1    scottr 
    167  1.1    scottr 
    168  1.4  christos void *
    169  1.4  christos nlm_granted_msg_1(struct nlm_testargs *argp, CLIENT *clnt)
    170  1.1    scottr {
    171  1.5  dholland 	enum clnt_stat st;
    172  1.1    scottr 	static char res;
    173  1.1    scottr 
    174  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    175  1.5  dholland 	st = clnt_call(clnt, NLM_GRANTED_MSG, xdr_nlm_testargs, argp, xdr_void,
    176  1.5  dholland 			&res, TIMEOUT);
    177  1.5  dholland 	if (st != RPC_SUCCESS) {
    178  1.4  christos 		return NULL;
    179  1.1    scottr 	}
    180  1.4  christos 	return &res;
    181  1.1    scottr }
    182  1.1    scottr 
    183  1.1    scottr 
    184  1.4  christos void *
    185  1.4  christos nlm_test_res_1(nlm_testres *argp, CLIENT *clnt)
    186  1.1    scottr {
    187  1.5  dholland 	enum clnt_stat st;
    188  1.1    scottr 	static char res;
    189  1.1    scottr 
    190  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    191  1.5  dholland 	st = clnt_call(clnt, NLM_TEST_RES, xdr_nlm_testres, argp, xdr_void,
    192  1.5  dholland 			&res, TIMEOUT);
    193  1.5  dholland 	if (st != RPC_SUCCESS) {
    194  1.4  christos 		return NULL;
    195  1.1    scottr 	}
    196  1.4  christos 	return &res;
    197  1.1    scottr }
    198  1.1    scottr 
    199  1.1    scottr 
    200  1.4  christos void *
    201  1.4  christos nlm_lock_res_1(nlm_res *argp, CLIENT *clnt)
    202  1.1    scottr {
    203  1.5  dholland 	enum clnt_stat st;
    204  1.1    scottr 	static char res;
    205  1.1    scottr 
    206  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    207  1.5  dholland 	st = clnt_call(clnt, NLM_LOCK_RES, xdr_nlm_res, argp, xdr_void,
    208  1.5  dholland 			&res, TIMEOUT);
    209  1.5  dholland 	if (st != RPC_SUCCESS) {
    210  1.4  christos 		return NULL;
    211  1.1    scottr 	}
    212  1.4  christos 	return &res;
    213  1.1    scottr }
    214  1.1    scottr 
    215  1.1    scottr 
    216  1.4  christos void *
    217  1.4  christos nlm_cancel_res_1(nlm_res *argp, CLIENT *clnt)
    218  1.1    scottr {
    219  1.5  dholland 	enum clnt_stat st;
    220  1.1    scottr 	static char res;
    221  1.1    scottr 
    222  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    223  1.5  dholland 	st = clnt_call(clnt, NLM_CANCEL_RES, xdr_nlm_res, argp, xdr_void,
    224  1.5  dholland 			&res, TIMEOUT);
    225  1.5  dholland 	if (st != RPC_SUCCESS) {
    226  1.4  christos 		return NULL;
    227  1.1    scottr 	}
    228  1.4  christos 	return &res;
    229  1.1    scottr }
    230  1.1    scottr 
    231  1.1    scottr 
    232  1.4  christos void *
    233  1.4  christos nlm_unlock_res_1(nlm_res *argp, CLIENT *clnt)
    234  1.1    scottr {
    235  1.5  dholland 	enum clnt_stat st;
    236  1.1    scottr 	static char res;
    237  1.1    scottr 
    238  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    239  1.5  dholland 	st = clnt_call(clnt, NLM_UNLOCK_RES, xdr_nlm_res, argp, xdr_void,
    240  1.5  dholland 			&res, TIMEOUT);
    241  1.5  dholland 	if (st != RPC_SUCCESS) {
    242  1.4  christos 		return NULL;
    243  1.1    scottr 	}
    244  1.4  christos 	return &res;
    245  1.1    scottr }
    246  1.1    scottr 
    247  1.1    scottr 
    248  1.4  christos void *
    249  1.4  christos nlm_granted_res_1(nlm_res *argp, CLIENT *clnt)
    250  1.1    scottr {
    251  1.5  dholland 	enum clnt_stat st;
    252  1.1    scottr 	static char res;
    253  1.1    scottr 
    254  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    255  1.5  dholland 	st = clnt_call(clnt, NLM_GRANTED_RES, xdr_nlm_res, argp, xdr_void,
    256  1.5  dholland 			&res, TIMEOUT);
    257  1.5  dholland 	if (st != RPC_SUCCESS) {
    258  1.4  christos 		return NULL;
    259  1.1    scottr 	}
    260  1.4  christos 	return &res;
    261  1.1    scottr }
    262  1.1    scottr 
    263  1.1    scottr 
    264  1.1    scottr nlm_shareres *
    265  1.4  christos nlm_share_3(nlm_shareargs *argp, CLIENT *clnt)
    266  1.1    scottr {
    267  1.5  dholland 	enum clnt_stat st;
    268  1.1    scottr 	static nlm_shareres res;
    269  1.1    scottr 
    270  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    271  1.5  dholland 	st = clnt_call(clnt, NLM_SHARE, xdr_nlm_shareargs, argp,
    272  1.5  dholland 			xdr_nlm_shareres, &res, TIMEOUT);
    273  1.5  dholland 	if (st != RPC_SUCCESS) {
    274  1.4  christos 		return NULL;
    275  1.1    scottr 	}
    276  1.4  christos 	return &res;
    277  1.1    scottr }
    278  1.1    scottr 
    279  1.1    scottr 
    280  1.1    scottr nlm_shareres *
    281  1.4  christos nlm_unshare_3(nlm_shareargs *argp, CLIENT *clnt)
    282  1.1    scottr {
    283  1.5  dholland 	enum clnt_stat st;
    284  1.1    scottr 	static nlm_shareres res;
    285  1.1    scottr 
    286  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    287  1.5  dholland 	st = clnt_call(clnt, NLM_UNSHARE, xdr_nlm_shareargs, argp,
    288  1.5  dholland 			xdr_nlm_shareres, &res, TIMEOUT);
    289  1.5  dholland 	if (st != RPC_SUCCESS) {
    290  1.4  christos 		return NULL;
    291  1.1    scottr 	}
    292  1.4  christos 	return &res;
    293  1.1    scottr }
    294  1.1    scottr 
    295  1.1    scottr 
    296  1.1    scottr nlm_res *
    297  1.4  christos nlm_nm_lock_3(nlm_lockargs *argp, CLIENT *clnt)
    298  1.1    scottr {
    299  1.5  dholland 	enum clnt_stat st;
    300  1.1    scottr 	static nlm_res res;
    301  1.1    scottr 
    302  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    303  1.5  dholland 	st = clnt_call(clnt, NLM_NM_LOCK, xdr_nlm_lockargs, argp, xdr_nlm_res,
    304  1.5  dholland 			&res, TIMEOUT);
    305  1.5  dholland 	if (st != RPC_SUCCESS) {
    306  1.4  christos 		return NULL;
    307  1.1    scottr 	}
    308  1.4  christos 	return &res;
    309  1.1    scottr }
    310  1.1    scottr 
    311  1.1    scottr 
    312  1.4  christos void *
    313  1.4  christos nlm_free_all_3(nlm_notify *argp, CLIENT *clnt)
    314  1.1    scottr {
    315  1.5  dholland 	enum clnt_stat st;
    316  1.1    scottr 	static char res;
    317  1.1    scottr 
    318  1.4  christos 	(void)memset(&res, 0, sizeof(res));
    319  1.5  dholland 	st = clnt_call(clnt, NLM_FREE_ALL, xdr_nlm_notify, argp, xdr_void,
    320  1.5  dholland 			&res, TIMEOUT);
    321  1.5  dholland 	if (st != RPC_SUCCESS) {
    322  1.4  christos 		return NULL;
    323  1.1    scottr 	}
    324  1.4  christos 	return &res;
    325  1.1    scottr }
    326  1.1    scottr 
    327  1.1    scottr 
    328  1.6  dholland int
    329  1.1    scottr main(int argc, char **argv)
    330  1.1    scottr {
    331  1.1    scottr 	CLIENT *cli;
    332  1.1    scottr 	nlm_res res_block;
    333  1.1    scottr 	nlm_res *out;
    334  1.1    scottr 	nlm_lockargs arg;
    335  1.1    scottr 	struct timeval tim;
    336  1.1    scottr 
    337  1.7  dholland 	if (argc != 2) {
    338  1.7  dholland 		errx(1, "usage: %s host", argv[0]);
    339  1.7  dholland 	}
    340  1.7  dholland 
    341  1.1    scottr 	printf("Creating client for host %s\n", argv[1]);
    342  1.1    scottr 	cli = clnt_create(argv[1], NLM_PROG, NLM_VERS, "udp");
    343  1.1    scottr 	if (!cli) {
    344  1.3     grant 		errx(1, "Failed to create client");
    345  1.1    scottr 		/* NOTREACHED */
    346  1.1    scottr 	}
    347  1.4  christos 	clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
    348  1.7  dholland 	printf("Default timeout was %lld.%d\n",
    349  1.7  dholland 		(long long)tim.tv_sec, tim.tv_usec);
    350  1.1    scottr 	tim.tv_usec = -1;
    351  1.1    scottr 	tim.tv_sec = -1;
    352  1.4  christos 	clnt_control(cli, CLSET_TIMEOUT, (void *)&tim);
    353  1.4  christos 	clnt_control(cli, CLGET_TIMEOUT, (void *)&tim);
    354  1.7  dholland 	printf("timeout now %lld.%u\n", (long long)tim.tv_sec, tim.tv_usec);
    355  1.1    scottr 
    356  1.1    scottr 
    357  1.1    scottr 	arg.cookie.n_len = 4;
    358  1.1    scottr 	arg.cookie.n_bytes = "hello";
    359  1.1    scottr 	arg.block = 0;
    360  1.1    scottr 	arg.exclusive = 0;
    361  1.1    scottr 	arg.reclaim = 0;
    362  1.1    scottr 	arg.state = 0x1234;
    363  1.1    scottr 	arg.alock.caller_name = "localhost";
    364  1.1    scottr 	arg.alock.fh.n_len = 32;
    365  1.1    scottr 	arg.alock.fh.n_bytes = "\x04\x04\x02\x00\x01\x00\x00\x00\x0c\x00\x00\x00\xff\xff\xff\xd0\x16\x00\x00\x5b\x7c\xff\xff\xff\xec\x2f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x19\x54\xef\xbf\xd7\x94";
    366  1.1    scottr 	arg.alock.oh.n_len = 8;
    367  1.1    scottr 	arg.alock.oh.n_bytes = "\x00\x00\x02\xff\xff\xff\xd3";
    368  1.1    scottr 	arg.alock.svid = 0x5678;
    369  1.1    scottr 	arg.alock.l_offset = 0;
    370  1.1    scottr 	arg.alock.l_len = 100;
    371  1.1    scottr 
    372  1.1    scottr 	res_block.stat.stat = nlm_granted;
    373  1.1    scottr 	res_block.cookie.n_bytes = "hello";
    374  1.1    scottr 	res_block.cookie.n_len = 5;
    375  1.1    scottr 
    376  1.1    scottr #if 0
    377  1.1    scottr 	if (nlm_lock_res_1(&res_block, cli))
    378  1.1    scottr 		printf("Success!\n");
    379  1.1    scottr 	else
    380  1.1    scottr 		printf("Fail\n");
    381  1.1    scottr #else
    382  1.7  dholland 	(void)res_block;
    383  1.7  dholland 
    384  1.8  dholland 	out = nlm_lock_msg_1(&arg, cli);
    385  1.8  dholland 	if (out != NULL) {
    386  1.1    scottr 		printf("Success!\n");
    387  1.7  dholland 		printf("out->stat = %d", out->stat.stat);
    388  1.1    scottr 	} else {
    389  1.1    scottr 		printf("Fail\n");
    390  1.1    scottr 	}
    391  1.1    scottr #endif
    392  1.1    scottr 
    393  1.1    scottr 	return 0;
    394  1.1    scottr }
    395