discovery.c (270279) | discovery.c (273543) |
---|---|
1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2012 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Edward Tomasz Napierala under sponsorship 6 * from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/usr.sbin/ctld/discovery.c 270279 2014-08-21 15:32:38Z trasz $"); | 32__FBSDID("$FreeBSD: head/usr.sbin/ctld/discovery.c 273543 2014-10-23 12:02:27Z trasz $"); |
33 34#include <assert.h> 35#include <stdint.h> 36#include <stdio.h> 37#include <stdlib.h> 38#include <string.h> 39#include <netinet/in.h> 40#include <netdb.h> --- 114 unchanged lines hidden (view full) --- 155 bhslr2->bhslr_statsn = htonl(conn->conn_statsn++); 156 bhslr2->bhslr_expcmdsn = htonl(conn->conn_cmdsn); 157 bhslr2->bhslr_maxcmdsn = htonl(conn->conn_cmdsn); 158 159 return (response); 160} 161 162static void | 33 34#include <assert.h> 35#include <stdint.h> 36#include <stdio.h> 37#include <stdlib.h> 38#include <string.h> 39#include <netinet/in.h> 40#include <netdb.h> --- 114 unchanged lines hidden (view full) --- 155 bhslr2->bhslr_statsn = htonl(conn->conn_statsn++); 156 bhslr2->bhslr_expcmdsn = htonl(conn->conn_cmdsn); 157 bhslr2->bhslr_maxcmdsn = htonl(conn->conn_cmdsn); 158 159 return (response); 160} 161 162static void |
163discovery_add_target(struct keys *response_keys, struct target *targ) | 163discovery_add_target(struct keys *response_keys, const struct target *targ) |
164{ 165 struct portal *portal; 166 char *buf; 167 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; 168 struct addrinfo *ai; 169 int ret; 170 171 keys_add(response_keys, "TargetName", targ->t_name); --- 29 unchanged lines hidden (view full) --- 201 } 202} 203 204void 205discovery(struct connection *conn) 206{ 207 struct pdu *request, *response; 208 struct keys *request_keys, *response_keys; | 164{ 165 struct portal *portal; 166 char *buf; 167 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; 168 struct addrinfo *ai; 169 int ret; 170 171 keys_add(response_keys, "TargetName", targ->t_name); --- 29 unchanged lines hidden (view full) --- 201 } 202} 203 204void 205discovery(struct connection *conn) 206{ 207 struct pdu *request, *response; 208 struct keys *request_keys, *response_keys; |
209 struct target *targ; | 209 const struct portal_group *pg; 210 const struct target *targ; |
210 const char *send_targets; 211 | 211 const char *send_targets; 212 |
213 pg = conn->conn_portal->p_portal_group; 214 |
|
212 log_debugx("beginning discovery session; waiting for Text PDU"); 213 request = text_receive(conn); 214 request_keys = keys_new(); 215 keys_load(request_keys, request); 216 217 send_targets = keys_find(request_keys, "SendTargets"); 218 if (send_targets == NULL) 219 log_errx(1, "received Text PDU without SendTargets"); 220 221 response = text_new_response(request); 222 response_keys = keys_new(); 223 224 if (strcmp(send_targets, "All") == 0) { | 215 log_debugx("beginning discovery session; waiting for Text PDU"); 216 request = text_receive(conn); 217 request_keys = keys_new(); 218 keys_load(request_keys, request); 219 220 send_targets = keys_find(request_keys, "SendTargets"); 221 if (send_targets == NULL) 222 log_errx(1, "received Text PDU without SendTargets"); 223 224 response = text_new_response(request); 225 response_keys = keys_new(); 226 227 if (strcmp(send_targets, "All") == 0) { |
225 TAILQ_FOREACH(targ, 226 &conn->conn_portal->p_portal_group->pg_conf->conf_targets, 227 t_next) { 228 if (targ->t_portal_group != 229 conn->conn_portal->p_portal_group) { | 228 TAILQ_FOREACH(targ, &pg->pg_conf->conf_targets, t_next) { 229 if (targ->t_portal_group != pg) { |
230 log_debugx("not returning target \"%s\"; " 231 "belongs to a different portal group", 232 targ->t_name); 233 continue; 234 } 235 discovery_add_target(response_keys, targ); 236 } 237 } else { | 230 log_debugx("not returning target \"%s\"; " 231 "belongs to a different portal group", 232 targ->t_name); 233 continue; 234 } 235 discovery_add_target(response_keys, targ); 236 } 237 } else { |
238 targ = target_find(conn->conn_portal->p_portal_group->pg_conf, 239 send_targets); | 238 targ = target_find(pg->pg_conf, send_targets); |
240 if (targ == NULL) { 241 log_debugx("initiator requested information on unknown " 242 "target \"%s\"; returning nothing", send_targets); 243 } else 244 discovery_add_target(response_keys, targ); 245 } 246 keys_save(response_keys, response); 247 --- 16 unchanged lines hidden --- | 239 if (targ == NULL) { 240 log_debugx("initiator requested information on unknown " 241 "target \"%s\"; returning nothing", send_targets); 242 } else 243 discovery_add_target(response_keys, targ); 244 } 245 keys_save(response_keys, response); 246 --- 16 unchanged lines hidden --- |