Changeset ebb1489 in mainline for uspace/srv/net/inetsrv/inetcfg.c
- Timestamp:
- 2024-10-13T08:23:40Z (8 weeks ago)
- Children:
- 0472cf17
- Parents:
- 2a0c827c (diff), b3b79981 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
- git-committer:
- GitHub <noreply@…> (2024-10-13 08:23:40)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inetsrv/inetcfg.c
r2a0c827c rebb1489 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 92 92 } 93 93 94 rc = inet_cfg_sync(cfg); 95 if (rc != EOK) { 96 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration."); 97 return rc; 98 } 99 94 100 return EOK; 95 101 } … … 98 104 { 99 105 inet_addrobj_t *addr; 106 inet_link_cfg_info_t info; 107 unsigned acnt; 108 inet_link_t *ilink; 109 errno_t rc; 110 111 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete()"); 100 112 101 113 addr = inet_addrobj_get_by_id(addr_id); … … 103 115 return ENOENT; 104 116 117 info.svc_id = addr->ilink->svc_id; 118 info.svc_name = str_dup(addr->ilink->svc_name); 119 if (info.svc_name == NULL) 120 return ENOMEM; 121 105 122 inet_addrobj_remove(addr); 106 123 inet_addrobj_delete(addr); 107 124 125 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): sync"); 126 127 rc = inet_cfg_sync(cfg); 128 if (rc != EOK) { 129 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration."); 130 free(info.svc_name); 131 return rc; 132 } 133 134 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): get link by ID"); 135 136 ilink = inet_link_get_by_id(info.svc_id); 137 if (ilink == NULL) { 138 log_msg(LOG_DEFAULT, LVL_ERROR, "Error finding link."); 139 return ENOENT; 140 } 141 142 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): check addrobj count"); 143 144 /* If there are no configured addresses left, autoconfigure link */ 145 acnt = inet_addrobj_cnt_by_link(ilink); 146 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): acnt=%u", acnt); 147 if (acnt == 0) 148 inet_link_autoconf_link(&info); 149 150 log_msg(LOG_DEFAULT, LVL_NOTE, "inetcfg_addr_delete(): DONE"); 108 151 return EOK; 109 152 } … … 193 236 inet_addr_t *router, sysarg_t *sroute_id) 194 237 { 238 errno_t rc; 195 239 inet_sroute_t *sroute; 196 240 … … 207 251 208 252 *sroute_id = sroute->id; 253 254 rc = inet_cfg_sync(cfg); 255 if (rc != EOK) { 256 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration."); 257 return rc; 258 } 259 209 260 return EOK; 210 261 } … … 212 263 static errno_t inetcfg_sroute_delete(sysarg_t sroute_id) 213 264 { 265 errno_t rc; 214 266 inet_sroute_t *sroute; 215 267 … … 220 272 inet_sroute_remove(sroute); 221 273 inet_sroute_delete(sroute); 274 275 rc = inet_cfg_sync(cfg); 276 if (rc != EOK) { 277 log_msg(LOG_DEFAULT, LVL_ERROR, "Error saving configuration."); 278 return rc; 279 } 222 280 223 281 return EOK; … … 805 863 } 806 864 865 static errno_t inet_cfg_load(const char *cfg_path) 866 { 867 sif_doc_t *doc = NULL; 868 sif_node_t *rnode; 869 sif_node_t *naddrs; 870 sif_node_t *nroutes; 871 const char *ntype; 872 errno_t rc; 873 874 rc = sif_load(cfg_path, &doc); 875 if (rc != EOK) 876 goto error; 877 878 rnode = sif_get_root(doc); 879 naddrs = sif_node_first_child(rnode); 880 ntype = sif_node_get_type(naddrs); 881 if (str_cmp(ntype, "addresses") != 0) { 882 rc = EIO; 883 goto error; 884 } 885 886 rc = inet_addrobjs_load(naddrs); 887 if (rc != EOK) 888 goto error; 889 890 nroutes = sif_node_next_child(naddrs); 891 ntype = sif_node_get_type(nroutes); 892 if (str_cmp(ntype, "static-routes") != 0) { 893 rc = EIO; 894 goto error; 895 } 896 897 rc = inet_sroutes_load(nroutes); 898 if (rc != EOK) 899 goto error; 900 901 sif_delete(doc); 902 return EOK; 903 error: 904 if (doc != NULL) 905 sif_delete(doc); 906 return rc; 907 908 } 909 910 static errno_t inet_cfg_save(const char *cfg_path) 911 { 912 sif_doc_t *doc = NULL; 913 sif_node_t *rnode; 914 sif_node_t *nsroutes; 915 sif_node_t *naddrobjs; 916 errno_t rc; 917 918 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_cfg_save(%s)", cfg_path); 919 920 rc = sif_new(&doc); 921 if (rc != EOK) 922 goto error; 923 924 rnode = sif_get_root(doc); 925 926 /* Address objects */ 927 928 rc = sif_node_append_child(rnode, "addresses", &naddrobjs); 929 if (rc != EOK) 930 goto error; 931 932 rc = inet_addrobjs_save(naddrobjs); 933 if (rc != EOK) 934 goto error; 935 936 /* Static routes */ 937 938 rc = sif_node_append_child(rnode, "static-routes", &nsroutes); 939 if (rc != EOK) 940 goto error; 941 942 rc = inet_sroutes_save(nsroutes); 943 if (rc != EOK) 944 goto error; 945 946 /* Save */ 947 948 rc = sif_save(doc, cfg_path); 949 if (rc != EOK) 950 goto error; 951 952 sif_delete(doc); 953 return EOK; 954 error: 955 if (doc != NULL) 956 sif_delete(doc); 957 return rc; 958 } 959 960 /** Open internet server configuration. 961 * 962 * @param cfg_path Configuration file path 963 * @param rcfg Place to store pointer to configuration object 964 * @return EOK on success or an error code 965 */ 966 errno_t inet_cfg_open(const char *cfg_path, inet_cfg_t **rcfg) 967 { 968 inet_cfg_t *cfg; 969 errno_t rc; 970 971 log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_cfg_open(%s)", cfg_path); 972 973 rc = inet_cfg_load(cfg_path); 974 if (rc != EOK) { 975 log_msg(LOG_DEFAULT, LVL_WARN, "inet_cfg_open(%s) :" 976 "could not load configuration.", cfg_path); 977 } 978 979 cfg = calloc(1, sizeof(inet_cfg_t)); 980 if (cfg == NULL) 981 return ENOMEM; 982 983 cfg->cfg_path = str_dup(cfg_path); 984 if (cfg->cfg_path == NULL) { 985 free(cfg); 986 return ENOMEM; 987 } 988 989 *rcfg = cfg; 990 return EOK; 991 } 992 993 errno_t inet_cfg_sync(inet_cfg_t *cfg) 994 { 995 log_msg(LOG_DEFAULT, LVL_NOTE, "inet_cfg_sync(cfg=%p)", cfg); 996 return inet_cfg_save(cfg->cfg_path); 997 } 998 999 void inet_cfg_close(inet_cfg_t *cfg) 1000 { 1001 free(cfg); 1002 } 1003 807 1004 /** @} 808 1005 */
Note:
See TracChangeset
for help on using the changeset viewer.