1 /* $OpenBSD: psm-opt.h,v 1.5 2012/05/08 13:18:37 yasuoka Exp $ */ 2 3 /*- 4 * Copyright (c) 2009 Internet Initiative Japan Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 #ifndef PSM_H 29 #define PSM_H 1 30 31 /**@file 32 * This files provides helper macros for negotiating configuration options. 33 *<p>Example:<pre> 34 * struct lcp { 35 * struct { 36 * uint8_t pfc; // bit flags for LCP PFC option 37 * uint8_t acfc; // bit flags for LCP ACFC option 38 * } opt; 39 * } 40 * if (psm_opt_is_accepted(lcp, pfc)) { 41 * // We've accepted "Protocol Field Compression" option. 42 * } 43 * // Mark peer rejects "Address and Control Field Compression" option. 44 * psm_peer_opt_set_reject(lcp, acfc, true) 45 * </pre></p> 46 * $Id: psm-opt.h,v 1.5 2012/05/08 13:18:37 yasuoka Exp $ 47 */ 48 49 #define PSM_OPT_REQUEST_OURS 0x01 50 #define PSM_OPT_ACCEPT_OURS 0x02 51 #define PSM_OPT_REJECT_OURS 0x04 52 #define PSM_OPT_ENABLED_OURS 0x08 53 54 #define PSM_OPT_REQUEST_PEERS 0x10 55 #define PSM_OPT_ACCEPT_PEERS 0x20 56 #define PSM_OPT_REJECT_PEERS 0x40 57 #define PSM_OPT_ENABLED_PEERS 0x80 58 59 #define psm_peer_opt_is_requested(psm, confopt) \ 60 (((psm)->opt.confopt & PSM_OPT_REQUEST_PEERS) != 0) 61 #define psm_peer_opt_set_requested(psm, confopt, boolval) \ 62 do { \ 63 if ((boolval)) { \ 64 (psm)->opt.confopt |= PSM_OPT_REQUEST_PEERS; \ 65 } else { \ 66 (psm)->opt.confopt &= ~PSM_OPT_REQUEST_PEERS; \ 67 } \ 68 } while (0) 69 #define psm_opt_is_requested(psm, confopt) \ 70 (((psm)->opt.confopt & PSM_OPT_REQUEST_OURS) != 0) 71 #define psm_opt_set_requested(psm, confopt, boolval) \ 72 do { \ 73 if ((boolval)) { \ 74 (psm)->opt.confopt |= PSM_OPT_REQUEST_OURS; \ 75 } else { \ 76 (psm)->opt.confopt &= ~PSM_OPT_REQUEST_OURS; \ 77 } \ 78 } while (0) 79 #define psm_peer_opt_is_accepted(psm, confopt) \ 80 (((psm)->opt.confopt & PSM_OPT_ACCEPT_PEERS) != 0) 81 #define psm_peer_opt_set_accepted(psm, confopt, boolval) \ 82 do { \ 83 if ((boolval)) { \ 84 (psm)->opt.confopt |= PSM_OPT_ACCEPT_PEERS; \ 85 } else { \ 86 (psm)->opt.confopt &= ~PSM_OPT_ACCEPT_PEERS; \ 87 } \ 88 } while (0) 89 #define psm_opt_is_accepted(psm, confopt) \ 90 (((psm)->opt.confopt & PSM_OPT_ACCEPT_OURS) != 0) 91 #define psm_opt_set_accepted(psm, confopt, boolval) \ 92 do { \ 93 if ((boolval)) { \ 94 (psm)->opt.confopt |= PSM_OPT_ACCEPT_OURS; \ 95 } else { \ 96 (psm)->opt.confopt &= ~PSM_OPT_ACCEPT_OURS; \ 97 } \ 98 } while (0) 99 #define psm_peer_opt_is_rejected(psm, confopt) \ 100 (((psm)->opt.confopt & PSM_OPT_REJECT_PEERS) != 0) 101 #define psm_peer_opt_set_rejected(psm, confopt, boolval) \ 102 do { \ 103 if ((boolval)) { \ 104 (psm)->opt.confopt |= PSM_OPT_REJECT_PEERS; \ 105 } else { \ 106 (psm)->opt.confopt &= ~PSM_OPT_REJECT_PEERS; \ 107 } \ 108 } while (0) 109 #define psm_opt_is_rejected(psm, confopt) \ 110 (((psm)->opt.confopt & PSM_OPT_REJECT_OURS) != 0) 111 #define psm_opt_set_rejected(psm, confopt, boolval) \ 112 do { \ 113 if ((boolval)) { \ 114 (psm)->opt.confopt |= PSM_OPT_REJECT_OURS; \ 115 } else { \ 116 (psm)->opt.confopt &= ~PSM_OPT_REJECT_OURS; \ 117 } \ 118 } while (0) 119 #define psm_peer_opt_is_enabled(psm, confopt) \ 120 (((psm)->opt.confopt & PSM_OPT_ENABLED_PEERS) != 0) 121 #define psm_peer_opt_set_enabled(psm, confopt, boolval) \ 122 do { \ 123 if ((boolval)) { \ 124 (psm)->opt.confopt |= PSM_OPT_ENABLED_PEERS; \ 125 } else { \ 126 (psm)->opt.confopt &= ~PSM_OPT_ENABLED_PEERS; \ 127 } \ 128 } while (0) 129 #define psm_opt_is_enabled(psm, confopt) \ 130 (((psm)->opt.confopt & PSM_OPT_ENABLED_OURS) != 0) 131 #define psm_opt_set_enabled(psm, confopt, boolval) \ 132 do { \ 133 if ((boolval)) { \ 134 (psm)->opt.confopt |= PSM_OPT_ENABLED_OURS; \ 135 } else { \ 136 (psm)->opt.confopt &= ~PSM_OPT_ENABLED_OURS; \ 137 } \ 138 } while (0) 139 #endif 140