fix wireguard set configuration
This commit is contained in:
		
							parent
							
								
									f5986a83f2
								
							
						
					
					
						commit
						97a5b5c7cb
					
				| @ -24,12 +24,10 @@ pub fn set_params(mut wg_pub_key: [u8; 32], | ||||
|                                                         CString::new(peer_ip).unwrap().into_raw(), | ||||
|                                                         51820); | ||||
| 
 | ||||
|         println!("crea la semilla"); | ||||
|         let mut device = wireguard_wrapper::generate_new_device(&mut wg_priv_key, | ||||
|                                                                 CString::new(interface_name).unwrap().into_raw(), | ||||
|                                                                 51820, peer); | ||||
| 
 | ||||
|         println!("crea la interfaz de red"); | ||||
|         //let status_add_device = wireguard_wrapper::wg_add_device(device.name.as_ptr());
 | ||||
|         let status_set_device = wireguard_wrapper::wg_set_device(&mut device); | ||||
|         //println!("dispositivo: {}", CString::from_raw(device.name.as_mut_ptr()).to_str().unwrap());
 | ||||
| @ -40,6 +38,7 @@ pub fn set_params(mut wg_pub_key: [u8; 32], | ||||
|         }*/ | ||||
|         //ret = status_add_device >= 0 && status_set_device >= 0;
 | ||||
|         ret = status_set_device >= 0; | ||||
|         log::debug!("Status: {}", ret); | ||||
|         wireguard_wrapper::clean_device(&mut peer); | ||||
|     } | ||||
|     ret | ||||
|  | ||||
| @ -19,15 +19,18 @@ wg_peer generate_new_peer(wg_key *pub_key, char *ip, unsigned short port) { | ||||
|   ipv4->next_allowedip = ipv6; | ||||
| 
 | ||||
|   wg_peer new_peer = { | ||||
| 		.flags = WGPEER_HAS_PUBLIC_KEY | WGPEER_REPLACE_ALLOWEDIPS, | ||||
| 		.flags = WGPEER_HAS_PUBLIC_KEY, | ||||
|     //.public_key = pub_key,
 | ||||
|     .first_allowedip = ipv4, | ||||
|     .last_allowedip = ipv6, | ||||
|     .endpoint = generate_endponit (ip, port), | ||||
| 	}; | ||||
| 
 | ||||
|   strcpy(new_peer.public_key, pub_key); | ||||
| 
 | ||||
|   printf("protocol 0.101: %d\n",new_peer.endpoint.addr.sa_family); | ||||
|   printf("protocol 0.102: %d\n",new_peer.endpoint.addr4.sin_family); | ||||
|   //strcpy(new_peer.public_key, pub_key);
 | ||||
|   memcpy(new_peer.public_key, pub_key, sizeof (wg_key)); | ||||
|   printf("protocol 0.111: %d\n",new_peer.endpoint.addr.sa_family); | ||||
|   printf("protocol 0.112: %d\n",new_peer.endpoint.addr4.sin_family); | ||||
|   return new_peer; | ||||
| } | ||||
| 
 | ||||
| @ -43,14 +46,22 @@ wg_device generate_new_device(wg_key *priv_key, | ||||
|     .first_peer = &peer, | ||||
|     .last_peer = &peer, | ||||
|   }; | ||||
|   strcpy(new_device.name, device_name); | ||||
|   strcpy(new_device.private_key, priv_key); | ||||
|   memcpy(new_device.name, device_name, sizeof (char[IFNAMSIZ])); | ||||
|   //strcpy(new_device.name, device_name);
 | ||||
|   memcpy(new_device.private_key, priv_key, sizeof (wg_key)); | ||||
|   //strcpy(new_device.private_key, priv_key);
 | ||||
|   printf("str2: %s\n",new_device.name); | ||||
|   wg_key_b64_string key, key2; | ||||
|   wg_key_to_base64(key, new_device.first_peer->public_key); | ||||
|   printf("str2: %s\n",key); | ||||
|   wg_key_to_base64(key2, new_device.private_key); | ||||
|   printf("str3: %s\n",key2); | ||||
|   printf("port: %d\n",new_device.first_peer->endpoint.addr4.sin_port); | ||||
|   printf("protocol 1: %d\n",new_device.first_peer->endpoint.addr.sa_family); | ||||
|   printf("protocol 2: %d\n",new_device.first_peer->endpoint.addr4.sin_family); | ||||
|   char str[INET_ADDRSTRLEN]; | ||||
|   inet_ntop(AF_INET, &(new_device.first_peer->endpoint.addr4.sin_addr), str, INET_ADDRSTRLEN); | ||||
|   printf("ip: %s\n", str); | ||||
|   return new_device; | ||||
| } | ||||
| 
 | ||||
| @ -59,7 +70,7 @@ wg_endpoint generate_endponit(char *ip, unsigned short port) { | ||||
|   inet_pton (AF_INET, ip, &ipv4); | ||||
|   struct sockaddr_in address = { | ||||
|     .sin_family = AF_INET, | ||||
|     .sin_port = port, | ||||
|     .sin_port = htons(port), | ||||
|     .sin_addr = ipv4, | ||||
|   }; | ||||
| 
 | ||||
| @ -67,6 +78,9 @@ wg_endpoint generate_endponit(char *ip, unsigned short port) { | ||||
|     .addr4 = address, | ||||
|   }; | ||||
| 
 | ||||
|   printf("protocol 0.1: %d\n",ret.addr.sa_family); | ||||
|   printf("protocol 0.2: %d\n",ret.addr4.sin_family); | ||||
| 
 | ||||
|   return ret; | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user