Both South Sudan's and Eritrea's independance referendum happened with the agreement of Sudan and Ethiopia.
=> a peace treaty in the case of Sudan => a consitutionnal provision in the case of Ethiopia
So they were legal.
Somalia will have to agree to letting Somaliland go in order for the African Union to recognize Somaliland independance.