* Find the first free unit number for a new interface. * Increase the size of the unit bitmap as necessary. */
| 110 | * Increase the size of the unit bitmap as necessary. |
| 111 | */ |
| 112 | static __inline void |
| 113 | ng_sppp_get_unit (int *unit) |
| 114 | { |
| 115 | int index, bit; |
| 116 | unsigned char mask; |
| 117 | |
| 118 | for (index = 0; index < ng_sppp_units_len |
| 119 | && ng_sppp_units[index] == 0xFF; index++); |
| 120 | if (index == ng_sppp_units_len) { /* extend array */ |
| 121 | unsigned char *newarray; |
| 122 | int newlen; |
| 123 | |
| 124 | newlen = (2 * ng_sppp_units_len) + sizeof (*ng_sppp_units); |
| 125 | newarray = malloc (newlen * sizeof (*ng_sppp_units), |
| 126 | M_NETGRAPH_SPPP, M_WAITOK); |
| 127 | bcopy (ng_sppp_units, newarray, |
| 128 | ng_sppp_units_len * sizeof (*ng_sppp_units)); |
| 129 | bzero (newarray + ng_sppp_units_len, |
| 130 | newlen - ng_sppp_units_len); |
| 131 | if (ng_sppp_units != NULL) |
| 132 | free (ng_sppp_units, M_NETGRAPH_SPPP); |
| 133 | ng_sppp_units = newarray; |
| 134 | ng_sppp_units_len = newlen; |
| 135 | } |
| 136 | mask = ng_sppp_units[index]; |
| 137 | for (bit = 0; (mask & 1) != 0; bit++) |
| 138 | mask >>= 1; |
| 139 | KASSERT ((bit >= 0 && bit < NBBY), |
| 140 | ("%s: word=%d bit=%d", __func__, ng_sppp_units[index], bit)); |
| 141 | ng_sppp_units[index] |= (1 << bit); |
| 142 | *unit = (index * NBBY) + bit; |
| 143 | ng_units_in_use++; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Free a no longer needed unit number. |
no test coverage detected